perm filename MF.TEX[MF,DEK] blob sn#745099 filedate 1984-03-11 generic text, type T, neo UTF8
\input webmac
% This program is copyright (C) 1984 by D. E. Knuth; all rights are reserved.
% Copying of this file is authorized only if (1) you are D. E. Knuth, or if
% (2) you make absolutely no changes to your copy. (The WEB system provides
% for alterations via an auxiliary file; the master file should stay intact.)
% In other words, METAFONT is under essentially the same ground rules as TeX.

% Version -1 is in preparation.

% A reward of $-5.12 will be paid to the first finder of any remaining bug.

% Places that say FIXTHIS are known to be deficient.
% Places that say xx are known to be missing a number to be filled in later.

% The following statement has been quoted from the TeX program.
% When this file is released to others, it will be true for METAFONT too!
% Begin quote:
% Although considerable effort has been expended to make the METAFONT program
% correct and reliable, no warranty is implied; the author disclaims any
% obligation or liability for damages, including but not limited to
% special, indirect, or consequential damages arising out of or in
% connection with the use or performance of this software. This work has
% been a ``labor of love'' and the author hopes that users enjoy it.
% End quote.

% Here is TeX material that gets inserted after \input webmac
\def\hang{\hangindent 3em\noindent\ignorespaces}
\def\textindent#1{\hangindent2.5em\noindent\hbox to2.5em{\hss#1 }\ignorespaces}
\font\ninerm=amr9
\let\mc=\ninerm % medium caps for names like PASCAL
\font\tenss=amss10 % for `The METAFONTbook'
\def\PASCAL{{\mc PASCAL}}
\def\ph{{\mc PASCAL-H}}
\font\logo=manfnt % font used for the METAFONT logo
\def\MF{{\logo META}\-{\logo FONT}}
\def\<#1>{$\langle#1\rangle$}
\def\section{\mathhexbox278}
\let\swap=\leftrightarrow
\def\round{\mathop{\rm round}\nolimits}

\def\(#1){} % this is used to make section names sort themselves better
\def\9#1{} % this is used for sort keys in the index via @:sort key}{entry@>

\outer\def\N#1. \[#2]#3.{\MN#1.\vfil\eject % begin starred section
  \def\rhead{PART #2:\uppercase{#3}} % define running headline
  \message{*\modno} % progress report
  \edef\next{\write\cont{\Z{\?#2]#3}{\modno}{\the\pageno}}}\next
  \ifon\startsection{\bf\ignorespaces#3.\quad}\ignorespaces}
\let\?=\relax % we want to be able to \write a \?

\def\title{{\logo opqrstuq}}
\def\topofcontents{\hsize 5.5in
	\centerline{\logo ()*+,-.*\titlefont\ (more or less)}
	\vfill
	\def\?##1]{\hbox to 1in{\hfil##1.\ }}
	}
\pageno=3

\N1.  \[1] Introduction.
\def\glob{13} % this should be the section number of "<Global...>"
\def\gglob{20, 26} % this should be the next two sections of "<Global...>"
This is \MF, a font compiler intended to produce high-quality typefaces.
The \PASCAL\ program that follows is the definition of \MF84, a standard
version of \MF\ that is designed to be highly portable so that identical output
will be obtainable on a great variety of different computers. Its conventions
are the same as those of \TeX82.

The main purpose of the following program is to explain the algorithms of \MF\
as clearly as possible. As a result, the program will not necessarily be very
efficient when a particular \PASCAL\ compiler has translated it into a
particular machine language. However, the program has been written so that it
can be tuned to run efficiently in a wide variety of operating environments
by making comparatively few changes. Such flexibility is possible because
the documentation that follows is written in the \.{WEB} language, which is
at a higher level than \PASCAL; the preprocessing step that converts \.{WEB}
to \PASCAL\ is able to introduce most of the necessary refinements.
Semi-automatic translation to other languages is also feasible, because the
program below does not make extensive use of features that are peculiar to
\PASCAL.

A large piece of software like \MF\ has inherent complexity that cannot
be reduced below a certain level of difficulty, although each individual
part is fairly simple by itself. The \.{WEB} language is intended to make
the algorithms as readable as possible, by reflecting the way the
individual program pieces fit together and by providing the
cross-references that connect different parts. Detailed comments about
what is going on, and about why things were done in certain ways, have
been liberally sprinkled throughout the program.  These comments explain
features of the implementation, but they rarely attempt to explain the
\MF\ language itself, since the reader is supposed to be familiar with
{\tenss The \MF book}.

\fi

\M2. The present implementation has a long ancestry, beginning in the spring
of~1977, when its author wrote a prototype set of subroutines and macros
that were used to develop the first Computer Modern fonts.
This original proto-\MF\ required the user to recompile a {\mc SAIL} program
whenever any character was changed, because it was not a ``language'' for
font design; the language was {\mc SAIL}. After several hundred characters
had been designed in that way, the author developed an interpretable language
called \MF, in which it was possible to express the Computer Modern programs
less cryptically. A complete \MF\ processor was designed and coded by the
author in 1979. This program, written in {\mc SAIL}, was adapted for use
with a variety of typesetting equipment and display terminals by Leo Guibas,
Lyle Ramshaw, and David Fuchs.
Major improvements to the design of Computer Modern fonts were made in the
spring of 1981, after which it became clear that a new language would
better express the needs of letterform designers. Therefore an entirely
new \MF\ language and system were designed in 1984; the present system
retains the name and some of the spirit of \MF79, but all of the details
have changed.

No doubt there still is plenty of room for enhancements, but the author
is firmly committed to keeping \MF84 ``frozen'' from now on; stability
and reliability are to be its main virtues.

On the other hand, the \.{WEB} description can be extended without changing
the core of \MF84 itself, and the program has been designed so that such
extensions are not extremely difficult to make.
The \\{banner} string defined here should be changed whenever \MF\
undergoes any modifications, so that it will be clear which version of
\MF\ might be the guilty party when a problem arises.

\Y\P\D \37$\\{banner}\S\.{\'This\ is\ METAFONT,\ Version\ -100.0\'}$\C{printed
when \MF\ starts}\par
\fi

\M3. Different \PASCAL s have slightly different conventions, and the present
\def\ph{{\mc PASCAL-H}}%
program expresses \MF\ in terms of the \PASCAL\ that was
available to the author in 1984. The methods used here to work with
this particular compiler, which we shall call \ph, should help the
reader to see how to make an appropriate interface for other systems
if necessary. (\ph\ is Charles Hedrick's modification of a compiler
for the DECsystem-10 that was originally developed at the University of
Hamburg; cf.\ {\sl SOFTWARE---Practice \AM\ Experience \bf6} (1976),
29--42. The \MF\ program below is intended to be adaptable, without
extensive changes, to most other versions of \PASCAL, so it does not fully
use the admirable features of \ph. Indeed, a conscious effort has been
made here to avoid using several idiosyncratic features of standard
\PASCAL\ itself, so that most of the code can be mechanically translated
into other high-level languages. For example, the `\&{with}' and `\\{new}'
features are not used, nor are pointer types, set types, or enumerated
scalar types; there are no `\&{var}' parameters, except in the case of files;
there are no tag fields on variant records; there are no \\{real} variables;
no procedures are declared local to other procedures.)

The portions of this program that involve system-dependent code, where
changes might be necessary because of differences between \PASCAL\ compilers
and/or differences between
operating systems, can be identified by looking at the sections whose
numbers are listed under `system dependencies' in the index. Furthermore,
the index entries for `dirty \PASCAL' list all places where the restrictions
of \PASCAL\ have not been followed perfectly, for one reason or another.

\fi

\M4. The program begins with a normal \PASCAL\ program heading, whose
components will be filled in later, using the conventions of \.{WEB}.
For example, the portion of the program called `\X\glob:Global
variables\X' here will be replaced by a sequence of variable declarations
that starts in $\section\glob$ of this documentation. In this way, we are able
to define each individual global variable when we are prepared to
understand what it means; we do not have to define all of the globals at
once.  Cross references in $\section\glob$, where it says ``See also
sections \gglob, \dots,'' also make it possible to look at the set of
all global variables, if desired.  Similar remarks apply to the other
portions of the program heading.

Actually the heading shown here is not quite normal: The  \&{program}\   line
does not mention any \\{output} file, because \ph\ would ask the \MF\ user
to specify a file name if \\{output} were specified here.

\Y\P\D \37$\\{mtype}\S\|t\J\|y\J\|p\J\|e$\C{this is a \.{WEB} coding trick:}\par
\P\F \37$\\{mtype}\S\\{type}$\C{`\&{mtype}' will be equivalent to `\&{type}'}%
\par
\P\F \37$\\{type}\S\\{true}$\C{but `\\{type}' will not be treated as a reserved
word}\par
\Y\P\hbox{\4}\X9:Compiler directives\X\6
\4\&{program}\1\  \37\\{MF};\C{all file names are defined dynamically}\6
\4\&{label} \37\X6:Labels in the outer block\X\6
\4\&{const} \37\X11:Constants in the outer block\X\6
\4\&{mtype} \37\X18:Types in the outer block\X\6
\4\&{var} \37\X13:Global variables\X\7
\4\&{procedure}\1\  \37\\{initialize};\C{this procedure gets things started
properly}\6
\4\&{var} \37\X19:Local variables for initialization\X\2\6
\&{begin} \37\X8:Initialize whatever \MF\ might access\X\6
\&{end};\7
\hbox{\4}\X57:Basic printing procedures\X\6
\hbox{\4}\X72:Error handling procedures\X\par
\fi

\M5. The overall \MF\ program begins with the heading just shown, after which
comes a bunch of procedure declarations and function declarations.
Finally we will get to the main program, which begins with the
comment `\\{start\_here}'. If you want to skip down to the
main program now, you can look up `\\{start\_here}' in the index.
But the author suggests that the best way to understand this program
is to follow pretty much the order of \MF's components as they appear in the
\.{WEB} description you are now reading, since the present ordering is
intended to combine the advantages of the ``bottom up'' and ``top down''
approaches to the problem of understanding a somewhat complicated system.

\fi

\M6. Three labels must be declared in the main program, so we give them
symbolic names.

\Y\P\D \37$\\{start\_of\_MF}=1$\C{go here when \MF's variables are initialized}%
\par
\P\D \37$\\{end\_of\_MF}=9998$\C{go here to close files and terminate
gracefully}\par
\P\D \37$\\{final\_end}=9999$\C{this label marks the ending of the program}\par
\Y\P$\4\X6:Labels in the outer block\X\S$\6
$\\{start\_of\_MF}\hbox{\hskip-2pt},\39\\{end\_of\_MF}\hbox{\hskip-2pt},\39\,%
\\{final\_end}$;\C{key control points}\par
\U section~4.\fi

\M7. Some of the code below is intended to be used only when diagnosing the
strange behavior that sometimes occurs when \MF\ is being installed or
when system wizards are fooling around with \MF\ without quite knowing
what they are doing. Such code will not normally be compiled; it is
delimited by the codewords `$ \&{debug} \ldots  \&{gubed} $', with apologies
to people who wish to preserve the purity of English. Similarly, there
is some conditional code delimited by `$ \&{stat} \ldots  \&{tats} $'
that is intended only for use when statistics
are to be kept about \MF's memory usage.

\Y\P\D \37$\\{debug}\S\B$\C{change this to `$\\{debug}\equiv\null$' when
debugging}\par
\P\D \37$\\{gubed}\S\hbox{}\T$\C{change this to `$\\{gubed}\equiv\null$' when
debugging}\par
\P\F \37$\\{debug}\S\\{begin}$\par
\P\F \37$\\{gubed}\S\\{end}$\Y\par
\P\D \37$\\{stat}\S\B$\C{change this to `$\\{stat}\equiv\null$' when gathering
	usage statistics}\par
\P\D \37$\\{tats}\S\hbox{}\T$\C{change this to `$\\{tats}\equiv\null$' when
gathering 	usage statistics}\par
\P\F \37$\\{stat}\S\\{begin}$\par
\P\F \37$\\{tats}\S\\{end}$\par
\fi

\M8. This program has two important variations: (1) There is a long and slow
version called \.{INIMF}, which does the extra calculations needed to
initialize \MF's internal tables; and (2)~there is a shorter and faster
production version, which cuts the initialization to a bare minimum.
Parts of the program that are needed in (1) but not in (2) are delimited by
the codewords `$ \&{init} \ldots  \&{tini} $'.

\Y\P\D \37$\\{init}\S$\C{change this to `$\\{init}\equiv\.{@\{}$' in the
production version}\par
\P\D \37$\\{tini}\S$\C{change this to `$\\{tini}\equiv\.{@\}}$' in the
production version}\par
\P\F \37$\\{init}\S\\{begin}$\par
\P\F \37$\\{tini}\S\\{end}$\par
\Y\P$\4\X8:Initialize whatever \MF\ might access\X\S$\6
\X21:Set initial values of key variables\X\6
\&{init} \37\X170:Initialize table entries (done by \.{INIMF} only)\X\ \&{tini}%
\par
\U section~4.\fi

\M9. If the first character of a \PASCAL\ comment is a dollar sign,
\ph\ treats the comment as a list of ``compiler directives'' that will
affect the translation of this program into machine language.  The
directives shown below specify full checking and inclusion of the \PASCAL\
debugger when \MF\ is being debugged, but they cause range checking and other
redundant code to be eliminated when the production system is being generated.
Arithmetic overflow will be detected in all cases.

\Y\P$\4\X9:Compiler directives\X\S$\6
$\B\J\$\|C-,\39\|A+,\39\|D-\T$\C{no range check, catch arithmetic overflow, no
debug overhead}\6
\&{debug} \37$\B\J\$\|C+,\39\|D+\T$\ \&{gubed}\C{but turn everything on when
debugging}\par
\U section~4.\fi

\M10. This \MF\ implementation conforms to the rules of the {\sl PASCAL User
Manual} published by Jensen and Wirth in 1975, except where system-dependent
code is necessary to make a useful system program, and except in another
respect where such conformity would unnecessarily obscure the meaning
and clutter up the code: We assume that   \&{case}  statements may include a
default case that applies if no matching label is found. Thus, we shall use
constructions like
$$\vbox{\halign{\ignorespaces#\hfil\cr
 \&{case} $\|x$ \&{of}\cr
1: $\langle\,$code for $x=1\,\rangle$;\cr
3: $\langle\,$code for $x=3\,\rangle$;\cr
 \&{othercases}  $\langle\,$code for $\|x\I1$ and $\|x\I3$$\,\rangle$\cr
  \&{endcases} \cr}}$$
since most \PASCAL\ compilers have plugged this hole in the language by
incorporating some sort of default mechanism. For example, the \ph\
compiler allows `\\{others}:' as a default label, and other \PASCAL s allow
syntaxes like `\ignorespaces \&{else} \unskip' or `\\{otherwise}' or
`\\{otherwise}:', etc. The definitions of  \&{othercases}  and   \&{endcases}
should be changed to agree with local conventions.  Note that no semicolon
appears before   \&{endcases}  in this program, so the definition of   %
\&{endcases}
should include a semicolon if the compiler wants one. (Of course, if no
default mechanism is available, the   \&{case}  statements of \MF\ will have
to be laboriously extended by listing all remaining cases. People who are
stuck with such \PASCAL s have in fact done this, successfully but not
happily!)

\Y\P\D \37$\\{othercases}\S\\{others}$: \37\C{default for cases not listed
explicitly}\par
\P\D \37$\\{endcases}\S$\ \&{end} \C{follows the default case in an extended   %
\&{case}  statement}\par
\P\F \37$\\{othercases}\S\\{else}$\par
\P\F \37$\\{endcases}\S\\{end}$\par
\fi

\M11. The following parameters can be changed at compile time to extend or
reduce \MF's capacity. They may have different values in \.{INIMF} and
in production versions of \MF.

\Y\P$\4\X11:Constants in the outer block\X\S$\6
$\\{mem\_max}=30000$;\C{greatest index in \MF's internal \\{mem} array, 	must
be strictly less than \\{max\_halfword}}\6
$\\{buf\_size}=500$;\C{maximum number of characters simultaneously present in
	current lines of open files; must not exceed \\{max\_halfword}}\6
$\\{error\_line}=72$;\C{width of context lines on terminal error messages}\6
$\\{half\_error\_line}=42$;\C{width of first lines of contexts in terminal
	error messages, should be between 30 and $\\{error\_line}-15$}\6
$\\{max\_print\_line}=79$;\C{width of longest text lines output, should be at
least 60}\6
$\\{screen\_width}=768$;\C{number of pixels in each row of screen display}\6
$\\{screen\_depth}=1024$;\C{number of pixels in each column of screen display}\6
$\\{stack\_size}=30$;\C{maximum number of simultaneous input sources}\6
$\\{max\_in\_open}=6$;\C{maximum number of input files and error insertions
that 	can be going on simultaneously}\6
$\\{param\_size}=30$;\C{maximum number of simultaneous macro parameters}\6
$\\{max\_strings}=1500$;\C{maximum number of strings; must not exceed \\{max%
\_halfword}}\6
$\\{string\_vacancies}=8000$;\C{the minimum number of characters that should be
	available for the user's identifier names, 	after \MF's own error messages are
stored}\6
$\\{pool\_size}=32000$;\C{maximum number of characters in strings, including
all 	error messages and help texts, and the names of all identifiers; 	must
exceed \\{string\_vacancies} by the total 	length of \MF's own strings, which
is currently about xxx}\6
$\\{save\_size}=200$;\C{space for saving values outside of current group, must
be 	at most \\{max\_halfword}}\6
$\\{move\_size}=5000$;\C{space for storing moves in a single octant}\6
$\\{gf\_buf\_size}=800$;\C{size of the output buffer, must be a multiple of 8}\6
$\\{file\_name\_size}=40$;\C{file names shouldn't be longer than this}\6
$\\{pool\_name}=\.{\'TeXformats:MF.POOL\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %
\ \ \'}$;\C{string of length \\{file\_name\_size}, tells where the string pool
appears}\6
$\\{path\_size}=100$;\C{maximum number of knots between breakpoints of a path}\6
$\\{bistack\_size}=154$;\C{size of stack for bisection algorithms, 	should
probably be left at this value}\par
\U section~4.\fi

\M12. Like the preceding parameters, the following quantities can be changed
at compile time to extend or reduce \MF's capacity. But if they are changed,
it is necessary to rerun the initialization program \.{INIMF}
to generate new tables for the production \MF\ program.
One can't simply make helter-skelter changes to the following constants,
since certain rather complex initialization
numbers are computed from them. They are defined here using
\.{WEB} macros, instead of being put into \PASCAL's  \&{const}  list, in order
to
emphasize this distinction.

\Y\P\D \37$\\{mem\_base}=0$\C{smallest index in the \\{mem} array, must not be
less 	than \\{min\_halfword}}\par
\P\D \37$\\{hi\_mem\_base}=13000$\C{smallest index in the single-word area of %
\\{mem}, 	must be substantially larger than \\{mem\_base} and smaller than %
\\{mem\_max}}\par
\P\D \37$\\{hash\_size}=2100$\C{maximum number of symbolic tokens, 	must be
less than $\\{max\_halfword}-3\ast\\{param\_size}$}\par
\P\D \37$\\{hash\_prime}=1777$\C{a prime number equal to about 85\% of \\{hash%
\_size}}\par
\fi

\M13. In case somebody has inadvertently made bad settings of the
``constants,''
\MF\ checks them using a global variable called \\{bad}.

This is the first of many sections of \MF\ where global variables are
defined.

\Y\P$\4\X13:Global variables\X\S$\6
\4\\{bad}: \37\\{integer};\C{is some ``constant'' wrong?}\par
\A sections~20, 26, 30, 32, 39, 50, 54, 67, 70, 73, 89, 94, 122, 130, 137, 141,
151, 152, 153, 154, 159, 172, 183, 186, 188, 190, 233, 243, 285, 289, 304, 312,
314, 330, 357, 365, 386, 402, 443, 474, 477, 480, 487, 494, 498, 501, 503, 504,
545, 586, 590, 602, 603, 610, 617, 622, 629, 645, 648, 666, 681, 787, 793,
and~810.
\U section~4.\fi

\M14. Later on we will say `\ignorespaces \&{if} $\\{mem\_max}\G\\{max%
\_halfword}$ \&{then} $\\{bad}\K10$',
or something similar. (We can't do that until \\{max\_halfword} has been
defined.)

\Y\P$\4\X14:Check the ``constant'' values for consistency\X\S$\6
$\\{bad}\K0$;\6
\&{if} $(\\{half\_error\_line}<30)\V(\\{half\_error\_line}>\\{error\_line}-15)$
\1\&{then}\5
$\\{bad}\K1$;\2\6
\&{if} $\\{max\_print\_line}<60$ \1\&{then}\5
$\\{bad}\K2$;\2\6
\&{if} $\\{gf\_buf\_size}\mathbin{\&{mod}}8\I0$ \1\&{then}\5
$\\{bad}\K3$;\2\6
\&{if} $(\\{hi\_mem\_base}<\\{mem\_base}+100)\V(\\{hi\_mem\_base}+100>\\{mem%
\_max})$ \1\&{then}\5
$\\{bad}\K4$;\2\6
\&{if} $\\{hash\_prime}>\\{hash\_size}$ \1\&{then}\5
$\\{bad}\K5$;\2\par
\A sections~147, 202, 315, and~612.
\U section~811.\fi

\M15. Labels are given symbolic names by the following definitions, so that
occasional \&{goto}  statements will be meaningful. We insert the label
`\\{exit}:' just before the `\ignorespaces  \&{end} \unskip' of a procedure in
which we have used the `\&{return}' statement defined below; the label
`\\{restart}' is occasionally used at the very beginning of a procedure; and
the label `\\{reswitch}' is occasionally used just prior to a   \&{case}
statement in which some cases change the conditions and we wish to branch
to the newly applicable case.  Loops that are set up with the  \~ \&{loop}
construction defined below are commonly exited by going to `\\{done}' or to
`\\{found}' or to `\\{not\_found}', and they are sometimes repeated by going to
`\\{continue}'.  If two or more parts of a subroutine start differently but
end up the same, the shared code may be gathered together at
`\\{common\_ending}'.

Incidentally, this program never declares a label that isn't actually used,
because some fussy \PASCAL\ compilers will complain about redundant labels.

\Y\P\D \37$\\{exit}=10$\C{go here to leave a procedure}\par
\P\D \37$\\{restart}=20$\C{go here to start a procedure again}\par
\P\D \37$\\{reswitch}=21$\C{go here to start a case statement again}\par
\P\D \37$\\{continue}=22$\C{go here to resume a loop}\par
\P\D \37$\\{done}=30$\C{go here to exit a loop}\par
\P\D \37$\\{done1}=31$\C{like \\{done}, when there is more than one loop}\par
\P\D \37$\\{done2}=32$\C{for exiting the second loop in a long block}\par
\P\D \37$\\{done3}=33$\C{for exiting the third loop in a very long block}\par
\P\D \37$\\{done4}=34$\C{for exiting the fourth loop in an extremely long
block}\par
\P\D \37$\\{done5}=35$\C{for exiting the fifth loop in an immense block}\par
\P\D \37$\\{done6}=36$\C{for exiting the sixth loop in a block}\par
\P\D \37$\\{found}=40$\C{go here when you've found it}\par
\P\D \37$\\{found1}=41$\C{like \\{found}, when there's more than one per
routine}\par
\P\D \37$\\{found2}=42$\C{like \\{found}, when there's more than two per
routine}\par
\P\D \37$\\{not\_found}=45$\C{go here when you've found nothing}\par
\P\D \37$\\{common\_ending}=50$\C{go here when you want to merge with another
branch}\par
\fi

\M16. Here are some macros for common programming idioms.

\Y\P\D \37$\\{incr}(\#)\S\#\K\#+1$\C{increase a variable by unity}\par
\P\D \37$\\{decr}(\#)\S\#\K\#-1$\C{decrease a variable by unity}\par
\P\D \37$\\{negate}(\#)\S\#\K-\#$\C{change the sign of a variable}\par
\P\D \37$\\{loop}\S$\ \&{while} $\\{true}$ \1\&{do}\ \C{repeat over and over
until a \&{goto}  happens}\par
\P\F \37$\\{loop}\S\\{xclause}$\C{\.{WEB}'s  \~ \&{xclause} acts like `%
\ignorespaces \&{while} $\\{true}$ \&{do}\unskip'}\par
\P\D \37$\\{do\_nothing}\S$\C{empty statement}\par
\P\D \37$\\{return}\S$\1\5
\&{goto} \37\\{exit}\C{terminate a procedure call}\2\par
\P\F \37$\\{return}\S\\{nil}$\par
\P\D \37$\\{empty}=0$\C{symbolic name for a null constant}\par
\fi

\N17.  \[2] The character set.
In order to make \MF\ readily portable between a wide variety of
computers, all of its input text is converted to an internal seven-bit
code that is essentially standard ASCII, the ``American Standard Code for
Information Interchange.''  This conversion is done immediately when each
character is read in. Conversely, characters are converted from ASCII to
the user's external representation just before they are output to a
text file.

Such an internal code is relevant to users of \MF\ only with respect to
constants that begin with a reverse apostrophe.

\fi

\M18. Characters of text that have been converted to \MF's internal form
are said to be of type \\{ASCII\_code}, which is a subrange of the integers.

\Y\P$\4\X18:Types in the outer block\X\S$\6
$\\{ASCII\_code}=0\to127$;\C{seven-bit numbers}\par
\A sections~25, 38, 97, 101, 102, 149, 473, 479, 497, and~647.
\U section~4.\fi

\M19. The original \PASCAL\ compiler was designed in the late 60s, when six-bit
character sets were common, so it did not make provision for lowercase
letters. Nowadays, of course, we need to deal with both capital and small
letters in a convenient way, especially in a program for font design;
so the present specification of \MF\ has been written under the assumption
that the \PASCAL\ compiler and run-time system permit the use of text files
with more than 64 distinguishable characters. More precisely, we assume that
the character set contains at least the letters and symbols associated
with ASCII codes \O{40} through \O{176}; all of these characters are now
available on most computer terminals.

Since we are dealing with more characters than were present in the first
\PASCAL\ compilers, we have to decide what to call the associated data
type. Some \PASCAL s use the original name \\{char} for the
characters in text files, even though there now are more than 64 such
characters, while other \PASCAL s consider \\{char} to be a 64-element
subrange of a larger data type that has some other name.

In order to accommodate this difference, we shall use the name \\{text\_char}
to stand for the data type of the characters that are converted to and
from \\{ASCII\_code} when they are input and output. We shall also assume
that \\{text\_char} consists of the elements $\\{chr}(\\{first\_text\_char})$
through
$\\{chr}(\\{last\_text\_char})$, inclusive. The following definitions should be
adjusted if necessary.

\Y\P\D \37$\\{text\_char}\S\\{char}$\C{the data type of characters in text
files}\par
\P\D \37$\\{first\_text\_char}=0$\C{ordinal number of the smallest element of %
\\{text\_char}}\par
\P\D \37$\\{last\_text\_char}=127$\C{ordinal number of the largest element of %
\\{text\_char}}\par
\Y\P$\4\X19:Local variables for initialization\X\S$\6
\4\|i: \37$0\to\\{last\_text\_char}$;\par
\A sections~123 and~169.
\U section~4.\fi

\M20. The \MF\ processor converts between ASCII code and
the user's external character set by means of arrays \\{xord} and \\{xchr}
that are analogous to \PASCAL's \\{ord} and \\{chr} functions.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{xord}: \37\&{array} $[\\{text\_char}]$ \1\&{of}\5
\\{ASCII\_code};\C{specifies conversion of input characters}\2\6
\4\\{xchr}: \37\&{array} $[\\{ASCII\_code}]$ \1\&{of}\5
\\{text\_char};\C{specifies conversion of output characters}\2\par
\fi

\M21. Since we are assuming that our \PASCAL\ system is able to read and write
the
visible characters of standard ASCII (although not necessarily using the
ASCII codes to represent them), the following assignment statements initialize
most of the \\{xchr} array properly, without needing any system-dependent
changes. On the other hand, it is possible to implement \MF\ with
less complete character sets, and in such cases it will be necessary to
change something here.

\Y\P$\4\X21:Set initial values of key variables\X\S$\6
$\\{xchr}[\O{40}]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{41}]\K\.{\'!\'}$;\5
$\\{xchr}[\O{42}]\K\.{\'"\'}$;\5
$\\{xchr}[\O{43}]\K\.{\'\#\'}$;\5
$\\{xchr}[\O{44}]\K\.{\'\$\'}$;\5
$\\{xchr}[\O{45}]\K\.{\'\%\'}$;\5
$\\{xchr}[\O{46}]\K\.{\'\&\'}$;\5
$\\{xchr}[\O{47}]\K\.{\'\'}\.{\'\'}$;\6
$\\{xchr}[\O{50}]\K\.{\'(\'}$;\5
$\\{xchr}[\O{51}]\K\.{\')\'}$;\5
$\\{xchr}[\O{52}]\K\.{\'*\'}$;\5
$\\{xchr}[\O{53}]\K\.{\'+\'}$;\5
$\\{xchr}[\O{54}]\K\.{\',\'}$;\5
$\\{xchr}[\O{55}]\K\.{\'-\'}$;\5
$\\{xchr}[\O{56}]\K\.{\'.\'}$;\5
$\\{xchr}[\O{57}]\K\.{\'/\'}$;\6
$\\{xchr}[\O{60}]\K\.{\'0\'}$;\5
$\\{xchr}[\O{61}]\K\.{\'1\'}$;\5
$\\{xchr}[\O{62}]\K\.{\'2\'}$;\5
$\\{xchr}[\O{63}]\K\.{\'3\'}$;\5
$\\{xchr}[\O{64}]\K\.{\'4\'}$;\5
$\\{xchr}[\O{65}]\K\.{\'5\'}$;\5
$\\{xchr}[\O{66}]\K\.{\'6\'}$;\5
$\\{xchr}[\O{67}]\K\.{\'7\'}$;\6
$\\{xchr}[\O{70}]\K\.{\'8\'}$;\5
$\\{xchr}[\O{71}]\K\.{\'9\'}$;\5
$\\{xchr}[\O{72}]\K\.{\':\'}$;\5
$\\{xchr}[\O{73}]\K\.{\';\'}$;\5
$\\{xchr}[\O{74}]\K\.{\'<\'}$;\5
$\\{xchr}[\O{75}]\K\.{\'=\'}$;\5
$\\{xchr}[\O{76}]\K\.{\'>\'}$;\5
$\\{xchr}[\O{77}]\K\.{\'?\'}$;\6
$\\{xchr}[\O{100}]\K\.{\'@\'}$;\5
$\\{xchr}[\O{101}]\K\.{\'A\'}$;\5
$\\{xchr}[\O{102}]\K\.{\'B\'}$;\5
$\\{xchr}[\O{103}]\K\.{\'C\'}$;\5
$\\{xchr}[\O{104}]\K\.{\'D\'}$;\5
$\\{xchr}[\O{105}]\K\.{\'E\'}$;\5
$\\{xchr}[\O{106}]\K\.{\'F\'}$;\5
$\\{xchr}[\O{107}]\K\.{\'G\'}$;\6
$\\{xchr}[\O{110}]\K\.{\'H\'}$;\5
$\\{xchr}[\O{111}]\K\.{\'I\'}$;\5
$\\{xchr}[\O{112}]\K\.{\'J\'}$;\5
$\\{xchr}[\O{113}]\K\.{\'K\'}$;\5
$\\{xchr}[\O{114}]\K\.{\'L\'}$;\5
$\\{xchr}[\O{115}]\K\.{\'M\'}$;\5
$\\{xchr}[\O{116}]\K\.{\'N\'}$;\5
$\\{xchr}[\O{117}]\K\.{\'O\'}$;\6
$\\{xchr}[\O{120}]\K\.{\'P\'}$;\5
$\\{xchr}[\O{121}]\K\.{\'Q\'}$;\5
$\\{xchr}[\O{122}]\K\.{\'R\'}$;\5
$\\{xchr}[\O{123}]\K\.{\'S\'}$;\5
$\\{xchr}[\O{124}]\K\.{\'T\'}$;\5
$\\{xchr}[\O{125}]\K\.{\'U\'}$;\5
$\\{xchr}[\O{126}]\K\.{\'V\'}$;\5
$\\{xchr}[\O{127}]\K\.{\'W\'}$;\6
$\\{xchr}[\O{130}]\K\.{\'X\'}$;\5
$\\{xchr}[\O{131}]\K\.{\'Y\'}$;\5
$\\{xchr}[\O{132}]\K\.{\'Z\'}$;\5
$\\{xchr}[\O{133}]\K\.{\'[\'}$;\5
$\\{xchr}[\O{134}]\K\.{\'\\\'}$;\5
$\\{xchr}[\O{135}]\K\.{\']\'}$;\5
$\\{xchr}[\O{136}]\K\.{\'\↑\'}$;\5
$\\{xchr}[\O{137}]\K\.{\'\_\'}$;\6
$\\{xchr}[\O{140}]\K\.{\'\`\'}$;\5
$\\{xchr}[\O{141}]\K\.{\'a\'}$;\5
$\\{xchr}[\O{142}]\K\.{\'b\'}$;\5
$\\{xchr}[\O{143}]\K\.{\'c\'}$;\5
$\\{xchr}[\O{144}]\K\.{\'d\'}$;\5
$\\{xchr}[\O{145}]\K\.{\'e\'}$;\5
$\\{xchr}[\O{146}]\K\.{\'f\'}$;\5
$\\{xchr}[\O{147}]\K\.{\'g\'}$;\6
$\\{xchr}[\O{150}]\K\.{\'h\'}$;\5
$\\{xchr}[\O{151}]\K\.{\'i\'}$;\5
$\\{xchr}[\O{152}]\K\.{\'j\'}$;\5
$\\{xchr}[\O{153}]\K\.{\'k\'}$;\5
$\\{xchr}[\O{154}]\K\.{\'l\'}$;\5
$\\{xchr}[\O{155}]\K\.{\'m\'}$;\5
$\\{xchr}[\O{156}]\K\.{\'n\'}$;\5
$\\{xchr}[\O{157}]\K\.{\'o\'}$;\6
$\\{xchr}[\O{160}]\K\.{\'p\'}$;\5
$\\{xchr}[\O{161}]\K\.{\'q\'}$;\5
$\\{xchr}[\O{162}]\K\.{\'r\'}$;\5
$\\{xchr}[\O{163}]\K\.{\'s\'}$;\5
$\\{xchr}[\O{164}]\K\.{\'t\'}$;\5
$\\{xchr}[\O{165}]\K\.{\'u\'}$;\5
$\\{xchr}[\O{166}]\K\.{\'v\'}$;\5
$\\{xchr}[\O{167}]\K\.{\'w\'}$;\6
$\\{xchr}[\O{170}]\K\.{\'x\'}$;\5
$\\{xchr}[\O{171}]\K\.{\'y\'}$;\5
$\\{xchr}[\O{172}]\K\.{\'z\'}$;\5
$\\{xchr}[\O{173}]\K\.{\'\{\'}$;\5
$\\{xchr}[\O{174}]\K\.{\'|\'}$;\5
$\\{xchr}[\O{175}]\K\.{\'\}\'}$;\5
$\\{xchr}[\O{176}]\K\.{\'\~\'}$;\6
$\\{xchr}[0]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{177}]\K\.{\'\ \'}$;\C{ASCII codes 0 and \O{177} do not appear in
text}\par
\A sections~23, 24, 68, 71, 74, 90, 95, 124, 131, 173, 189, 191, 234, 244, 313,
387, 413, 478, 587, 611, 646, 649, 667, 682, and~788.
\U section~8.\fi

\M22. Some of the ASCII codes without visible characters have been given
symbolic
names in this program because they are used with a special meaning.

\Y\P\D \37$\\{null\_code}=\O{0}$\C{ASCII code that might disappear}\par
\P\D \37$\\{carriage\_return}=\O{15}$\C{ASCII code used at end of line}\par
\P\D \37$\\{invalid\_code}=\O{177}$\C{ASCII code that should not appear}\par
\fi

\M23. The ASCII code is ``standard'' only to a certain extent, since many
computer installations have found it advantageous to have ready access
to more than 94 printing characters. Appendix~C of {\sl The \TeX book\/}
gives a complete specification of the intended correspondence between
characters and \MF's internal representation.

If \MF\ is being used
on a garden-variety \PASCAL\ for which only standard ASCII
codes will appear in the input and output files, it doesn't really matter
what codes are specified in $\\{xchr}[1\to\O{37}]$, but the safest policy is to
blank everything out by using the code shown below.

However, other settings of \\{xchr} will make \MF\ more friendly on
computers that have an extended character set, so that users can type things
like `\.↑↑Z' instead of `\.{<>}'. At MIT, for example, it would be more
appropriate to substitute the code
$$\hbox{ \&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \&{do} $\\{xchr}[\|i]\K\\{chr}(%
\|i)$;}$$
\MF's character set is essentially the same as MIT's, even with respect to
characters less than~\O{40}. People with extended character sets can
assign codes arbitrarily, giving an \\{xchr} equivalent to whatever
characters the users of \MF\ are allowed to have in their input files.
It is best to make the codes correspond to the intended interpretations as
shown in Appendix~C whenever possible; but this is not necessary. For
example, in countries with an alphabet of more than 26 letters, it is
usually best to map the additional letters into codes less than~\O{40}.
Appropriate changes to \MF's category code table should then be made.
(Unlike \TeX, each installation of \MF\ has a fixed assignment of category
codes.)

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \1\&{do}\5
$\\{xchr}[\|i]\K\.{\'\ \'}$;\2\par
\fi

\M24. The following system-independent code makes the \\{xord} array contain a
suitable inverse to the information in \\{xchr}. Note that if $\\{xchr}[\|i]=%
\\{xchr}[\|j]$
where $\|i<\|j<\O{177}$, the value of $\\{xord}[\\{xchr}[\|i]]$ will turn out
to be
\|j or more; hence, standard ASCII code numbers will be used instead of
codes below \O{40} in case there is a coincidence.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|i\K\\{first\_text\_char}\mathrel{\&{to}}\\{last\_text\_char}$ \1%
\&{do}\5
$\\{xord}[\\{chr}(\|i)]\K\\{invalid\_code}$;\2\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{176}$ \1\&{do}\5
$\\{xord}[\\{xchr}[\|i]]\K\|i$;\2\par
\fi

\N25.  \[3] Input and output.
The bane of portability is the fact that different operating systems treat
input and output quite differently, perhaps because computer scientists
have not given sufficient attention to this problem. People have felt somehow
that input and output are not a part of ``real'' programming. Well, it is true
that some kinds of programming are more fun than others. With existing
input/output conventions being so diverse and so messy, the only sources of
joy in such parts of the code are the rare occasions when one can find a
way to make the program a little less bad than it might have been. We have
two choices: whether to attack I/O now and get it over with, or to postpone
it until near the end. Neither prospect is very attractive, so let's
get it over with.

The basic operations we need to do are (1)~inputting and outputting of
text, to or from a file or the user's terminal; (2)~inputting and
outputting of eight-bit bytes, to or from a file; (3)~instructing the
operating system to initiate (``open'') or to terminate (``close'') input or
output from a specified file; (4)~testing whether the end of an input
file has been reached; (5)~display of bits on the user's screen.
The bit-display operation will be discussed in a later section; we shall
deal here only with more traditional kinds of I/O.

Note that \MF\ needs to deal with only two kinds of files.
We shall use the term \\{alpha\_file} for a file that contains textual data,
and the term \\{byte\_file} for a file that contains eight-bit binary
information.
These two types turn out to be the same on many computers, but
sometimes there is a significant distinction, so we shall be careful to
distinguish between them. Standard protocols for transferring
such files from computer to computer, via high-speed networks, are
now becoming available to more and more communities of users.

\MF\ actually makes use also of a third kind of file, called a \\{word\_file},
when dumping and reloading base information for its own initialization.
We shall define a word file later; but it will be possible for us to
do a few simple things with them in this section before they are defined.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{eight\_bits}=0\to255$;\C{unsigned one-byte quantity}\6
$\\{alpha\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{text\_char};\C{files that contain textual data}\2\2\6
$\\{byte\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{eight\_bits};\C{files that contain binary data}\2\2\par
\fi

\M26. Most of what we need to do with respect to input and output can be
handled
by the I/O facilities that are standard in \PASCAL, i.e., the routines
called \\{get}, \\{put}, \\{eof}, and so on. But
standard \PASCAL\ does not allow file variables to be associated with file
names that are determined at run time, so it cannot be used to implement
\MF; some sort of extension to \PASCAL's ordinary \\{reset} and \\{rewrite}
is crucial for our purposes. We shall assume that \\{name\_of\_file} is a
variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \MF\ can open a file whose external name is specified by
\\{name\_of\_file}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{name\_of\_file}: \37\&{packed} \37\&{array} $[1\to\\{file\_name\_size}]$ %
\1\&{of}\5
\\{char};\2\6
\C{on some systems this may be a \&{record} variable}\6
\4\\{name\_length}: \37$0\to\\{file\_name\_size}$;\6
\C{this many characters are actually 	relevant in \\{name\_of\_file} (the rest
are blank)}\par
\fi

\M27. The \ph\ compiler with which the present version of \MF\ was prepared has
extended the rules of \PASCAL\ in a very convenient way. To open file~\|f,
we can write
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr
$\\{reset}(\|f,\hbox{\\{name}},\.{\'/O\'})$&for input;\cr
$\\{rewrite}(\|f,\hbox{\\{name}},\.{\'/O\'})$&for output.\cr}}$$
The `\\{name}' parameter, which is of type `\ignorespaces\&{packed} \&{array}
$[\hbox{\<\\{any}>}]$ \&{of} \\{text\_char}', stands for the name of
the external file that is being opened for input or output.
Blank spaces that might appear in \\{name} are ignored.

The `\.{/O}' parameter tells the operating system not to issue its own
error messages if something goes wrong. If a file of the specified name
cannot be found, or if such a file cannot be opened for some other reason
(e.g., someone may already be trying to write the same file), we will have
$\\{erstat}(\|f)\I0$ after an unsuccessful \\{reset} or \\{rewrite}.  This
allows
\MF\ to undertake appropriate corrective action.

\MF's file-opening procedures return \\{false} if no file identified by
\\{name\_of\_file} could be opened.

\Y\P\D \37$\\{reset\_OK}(\#)\S\\{erstat}(\#)=0$\par
\P\D \37$\\{rewrite\_OK}(\#)\S\\{erstat}(\#)=0$\par
\Y\P\4\&{function}\1\  \37$\\{a\_open\_in}(\mathop{\&{var}}\|f:\\{alpha%
\_file})$: \37\\{boolean};\C{open a text file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{a\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{a\_open\_out}(\mathop{\&{var}}\|f:\\{alpha\_file})$: %
\37\\{boolean};\C{open a text file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{a\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{b\_open\_in}(\mathop{\&{var}}\|f:\\{byte\_file})$: %
\37\\{boolean};\C{open a binary file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{b\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{b\_open\_out}(\mathop{\&{var}}\|f:\\{byte\_file})$: %
\37\\{boolean};\C{open a binary file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{b\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{w\_open\_in}(\mathop{\&{var}}\|f:\\{word\_file})$: %
\37\\{boolean};\C{open a word file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{w\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{w\_open\_out}(\mathop{\&{var}}\|f:\\{word\_file})$: %
\37\\{boolean};\C{open a word file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O\'})$;\5
$\\{w\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\par
\fi

\M28. Files can be closed with the \ph\ routine `$\\{close}(\|f)$', which
should be used when all input or output with respect to \|f has been completed.
This makes \|f available to be opened again, if desired; and if \|f was used
for
output, the \\{close} operation makes the corresponding external file appear
on the user's area, ready to be read.

\Y\P\4\&{procedure}\1\  \37$\\{a\_close}(\mathop{\&{var}}\|f:\\{alpha\_file})$;%
\C{close a text file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{b\_close}(\mathop{\&{var}}\|f:\\{byte\_file})$;%
\C{close a binary file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{w\_close}(\mathop{\&{var}}\|f:\\{word\_file})$;%
\C{close a word file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\par
\fi

\M29. Binary input and output are done with \PASCAL's ordinary \\{get} and %
\\{put}
procedures, so we don't have to make any other special arrangements for
binary~I/O. Text output is also easy to do with standard \PASCAL\ routines.
The treatment of text input is more difficult, however, because
of the necessary translation to \\{ASCII\_code} values, and because
\MF's conventions should be efficient and they should
blend nicely with the user's operating environment.

\fi

\M30. Input from text files is read one line at a time, using a routine called
\\{input\_ln}. This function is defined in terms of global variables called
\\{buffer}, \\{first}, and \\{last} that will be described in detail later; for
now, it suffices for us to know that \\{buffer} is an array of \\{ASCII\_code}
values, and that \\{first} and \\{last} are indices into this array
representing the beginning and ending of a line of text.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{buffer}: \37\&{array} $[0\to\\{buf\_size}]$ \1\&{of}\5
\\{ASCII\_code};\C{lines of characters being read}\2\6
\4\\{first}: \37$0\to\\{buf\_size}$;\C{the first unused position in \\{buffer}}%
\6
\4\\{last}: \37$0\to\\{buf\_size}$;\C{end of the line just input to \\{buffer}}%
\6
\4\\{max\_buf\_stack}: \37$0\to\\{buf\_size}$;\C{largest index used in %
\\{buffer}}\par
\fi

\M31. The \\{input\_ln} function brings the next line of input from the
specified
field into available positions of the buffer array and returns the value
\\{true}, unless the file has already been entirely read, in which case it
returns \\{false} and sets $\\{last}\K\\{first}$.  In general, the \\{ASCII%
\_code}
numbers that represent the next line of the file are input into
$\\{buffer}[\\{first}]$, $\\{buffer}[\\{first}+1]$, \dots, $\\{buffer}[%
\\{last}-1]$; and the
global variable \\{last} is set equal to \\{first} plus the length of the
line. Trailing blanks are removed from the line; thus, either $\\{last}=%
\\{first}$
(in which case the line was entirely blank) or $\\{buffer}[\\{last}-1]\I\.{"\
"}$.

An overflow error is given, however, if the normal actions of \\{input\_ln}
would make $\\{last}\G\\{buf\_size}$; this is done so that other parts of \MF\
can safely look at the contents of $\\{buffer}[\\{last}+1]$ without
overstepping
the bounds of the \\{buffer} array. Upon entry to \\{input\_ln}, the condition
$\\{first}<\\{buf\_size}$ will always hold, so that there is always room for an
``empty'' line.

The variable \\{max\_buf\_stack}, which is used to keep track of how large
the \\{buf\_size} parameter must be to accommodate the present job, is
also kept up to date by \\{input\_ln}.

If the \\{bypass\_eoln} parameter is \\{true}, \\{input\_ln} will do a \\{get}
before looking at the first character of the line; this skips over
an \\{eoln} that was in $\|f\↑$. The procedure does not do a \\{get} when it
reaches the end of the line; therefore it can be used to acquire input
from the user's terminal as well as from ordinary text files.

Standard \PASCAL\ says that a file should have \\{eoln} immediately
before \\{eof}, but \MF\ needs only a weaker restriction: If \\{eof}
occurs in the middle of a line, the system function \\{eoln} should return
a \\{true} result (even though $\|f\↑$ will be undefined).

\Y\P\4\&{function}\1\  \37$\\{input\_ln}(\mathop{\&{var}}\|f:\\{alpha\_file};\,%
\35\\{bypass\_eoln}:\\{boolean})$: \37\\{boolean};\C{inputs the next line or
returns \\{false}}\6
\4\&{var} \37\\{last\_nonblank}: \37$0\to\\{buf\_size}$;\C{\\{last} with
trailing blanks removed}\2\6
\&{begin} \37\&{if} $\\{bypass\_eoln}$ \1\&{then}\6
\&{if} $\R\\{eof}(\|f)$ \1\&{then}\5
$\\{get}(\|f)$;\C{input the first character of the line into $\|f\↑$}\2\2\6
$\\{last}\K\\{first}$;\C{cf.\ Matthew 19:30}\6
\&{if} $\\{eof}(\|f)$ \1\&{then}\5
$\\{input\_ln}\K\\{false}$\6
\4\&{else} \&{begin} \37$\\{last\_nonblank}\K\\{first}$;\6
\&{while} $\R\\{eoln}(\|f)$ \1\&{do}\6
\&{begin} \37\&{if} $\\{last}\G\\{max\_buf\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_buf\_stack}\K\\{last}+1$;\6
\&{if} $\\{max\_buf\_stack}=\\{buf\_size}$ \1\&{then}\5
$\\{overflow}(\.{"buffer\ size"},\39\\{buf\_size})$;\2\6
\&{end};\2\6
$\\{buffer}[\\{last}]\K\\{xord}[\|f\↑]$;\5
$\\{get}(\|f)$;\5
$\\{incr}(\\{last})$;\6
\&{if} $\\{buffer}[\\{last}-1]\I\.{"\ "}$ \1\&{then}\5
$\\{last\_nonblank}\K\\{last}$;\2\6
\&{end};\2\6
$\\{last}\K\\{last\_nonblank}$;\5
$\\{input\_ln}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M32. The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file variable is called \\{term\_in}, and when it
is considered an output file the file variable is \\{term\_out}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{term\_in}: \37\\{alpha\_file};\C{the terminal as an input file}\6
\4\\{term\_out}: \37\\{alpha\_file};\C{the terminal as an output file}\par
\fi

\M33. Here is how to open the terminal files
in \ph. The `\.{/I}' switch suppresses the first \\{get}.

\Y\P\D \37$\\{t\_open\_in}\S\\{reset}(\\{term\_in},\39\.{\'TTY:\'},\39\.{\'/O/I%
\'})$\C{open the terminal for text input}\par
\P\D \37$\\{t\_open\_out}\S\\{rewrite}(\\{term\_out},\39\.{\'TTY:\'},\39\.{\'/O%
\'})$\C{open the terminal for text output}\par
\fi

\M34. Sometimes it is necessary to synchronize the input/output mixture that
happens on the user's terminal, and three procedures are used for this
purpose. The first of these, \\{update\_terminal}, is called when we want
to make sure that everything we have output to the terminal so far has
actually left the computer's internal buffers and been sent.
The second, \\{clear\_terminal}, is called when we wish to cancel any
input that the user may have typed ahead (since we are about to
issue an unexpected error message). The third, \\{wake\_up\_terminal},
is supposed to revive the terminal if the user has disabled it by
some instruction to the operating system.  The following macros show how
these operations can be specified in \ph:

\Y\P\D \37$\\{update\_terminal}\S\\{break}(\\{term\_out})$\C{empty the terminal
output buffer}\par
\P\D \37$\\{clear\_terminal}\S\\{break\_in}(\\{term\_in},\39\\{true})$\C{clear
the terminal input buffer}\par
\P\D \37$\\{wake\_up\_terminal}\S\\{do\_nothing}$\C{cancel the user's
cancellation of output}\par
\fi

\M35. We need a special routine to read the first line of \MF\ input from
the user's terminal. This line is different because it is read before we
have opened the transcript file; there is sort of a ``chicken and
egg'' problem here. If the user types `\.{input paper}' on the first
line, or if some macro invoked by that line does such an \.{input},
the transcript file will be named `\.{paper.log}'; but if no \.{input}
commands are performed during the first line of terminal input, the transcript
file will acquire its default name `\.{mfput.log}'. (The transcript file
will not contain error messages generated by the first line before the
first \.{input} command.)

The first line is even more special if we are lucky enough to have an operating
system that treats \MF\ differently from a run-of-the-mill \PASCAL\ object
program. It's nice to let the user start running a \MF\ job by typing
a command line like `\.{MF cmr10}'; in such a case, \MF\ will operate
as if the first line of input were `\.{cmr10}', i.e., the first line will
consist of the remainder of the command line, after the part that invoked \MF.

\fi

\M36. Different systems have different ways to get started, but regardless of
what conventions are adopted the routine that initializes the terminal
should satisfy the following specifications:

\yskip\textindent{1)}It should open file \\{term\_in} for input from the
terminal. (The file \\{term\_out} will already be open for output to the
terminal.)

\textindent{2)}If the user has given a command line, this line should be
considered the first line of terminal input. Otherwise the
user should be prompted with `\.{**}', and the first line of input
should be whatever is typed in response.

\textindent{3)}The first line of input, which might or might not be a
command line, should appear in locations \\{first} to $\\{last}-1$ of the
\\{buffer} array.

\textindent{4)}The global variable \\{loc} should be set so that the
character that \MF\ reads next is in $\\{buffer}[\\{loc}]$. This
character should not be blank, and we should have $\\{loc}<\\{last}$.

\yskip\noindent(It may be necessary to prompt the user several times
before a non-blank line comes in. The prompt is `\.{**}' instead of the
later `\.*' because the meaning is slightly different: `\.{input}' need
not be typed immediately after~`\.{**}'.)

\Y\P\D \37$\\{loc}\S\\{cur\_input}.\\{loc\_field}$\C{location of first unread
character in \\{buffer}}\par
\fi

\M37. The following program does the required initialization
without retrieving a possible command line.
It should be clear how to modify this routine to deal with command lines,
if the system permits them.

\Y\P\4\&{function}\1\  \37\\{init\_terminal}: \37\\{boolean};\C{gets the
terminal input started}\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\\{t\_open\_in};\6
\~ \1\&{loop}\ \&{begin} \37\\{wake\_up\_terminal};\5
$\\{write}(\\{term\_out},\39\.{\'**\'})$;\5
\\{update\_terminal};\6
\&{if} $\R\\{input\_ln}(\\{term\_in},\39\\{true})$ \1\&{then}\C{this shouldn't
happen}\6
\&{begin} \37$\\{write\_ln}(\\{term\_out})$;\5
$\\{write}(\\{term\_out},\39\.{\'!\ End\ of\ file\ on\ the\ terminal...\ why?%
\'})$;\5
$\\{init\_terminal}\K\\{false}$;\5
\&{return};\6
\&{end};\2\6
$\\{loc}\K\\{first}$;\6
\&{while} $(\\{loc}<\\{last})\W(\\{buffer}[\\{loc}]=\.{"\ "})$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{if} $\\{loc}<\\{last}$ \1\&{then}\6
\&{begin} \37$\\{init\_terminal}\K\\{true}$;\5
\&{return};\C{return unless the line was all blank}\6
\&{end};\2\6
$\\{write\_ln}(\\{term\_out},\39\.{\'Please\ type\ the\ name\ of\ your\ input\
file.\'})$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\N38.  \[4] String handling.
Control sequence names and diagnostic messages are variable-length strings
of seven-bit characters. Since \PASCAL\ does not have a well-developed string
mechanism, \MF\ does all of its string processing by homegrown methods.

Elaborate facilities for dynamic strings are not needed, so all of the
necessary operations can be handled with a simple data structure.
The array \\{str\_pool} contains all of the (seven-bit) ASCII codes in all
of the strings, and the array \\{str\_start} contains indices of the starting
points of each string. Strings are referred to by integer numbers, so that
string number \|s comprises the characters $\\{str\_pool}[\|j]$ for
$\\{str\_start}[\|s]\L\|j<\\{str\_start}[\|s+1]$. Additional integer variables
\\{pool\_ptr} and \\{str\_ptr} indicate the number of entries used so far
in \\{str\_pool} and \\{str\_start}, respectively; locations
$\\{str\_pool}[\\{pool\_ptr}]$ and $\\{str\_start}[\\{str\_ptr}]$ are
ready for the next string to be allocated.

String numbers 0 to 127 are reserved for strings that correspond to single
ASCII characters. This is in accordance with the conventions of \.{WEB},
which converts single-character strings into the ASCII code number of the
single character involved, while it converts other strings into integers
and builds a string pool file. Thus, when the string constant \.{"."} appears
in the program below, \.{WEB} converts it into the integer 46, which is the
ASCII code for a period, while \.{WEB} will convert a string like \.{"hello"}
into some integer greater than~127. String number 46 will presumably be the
single character `\..'; but some ASCII codes have no standard visible
representation, and \MF\ sometimes needs to be able to print an arbitrary
ASCII character, so the first 128 strings are used to specify exactly what
should be printed for each of the 128 possibilities.

Elements of the \\{str\_pool} array must be ASCII codes that can actually be
printed; i.e., they must have an \\{xchr} equivalent in the local
character set.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{pool\_pointer}=0\to\\{pool\_size}$;\C{for variables that point into \\{str%
\_pool}}\6
$\\{str\_number}=0\to\\{max\_strings}$;\C{for variables that point into \\{str%
\_start}}\par
\fi

\M39. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{str\_pool}: \37\&{packed} \37\&{array} $[\\{pool\_pointer}]$ \1\&{of}\5
\\{ASCII\_code};\C{the characters}\2\6
\4\\{str\_start}: \37\&{array} $[\\{str\_number}]$ \1\&{of}\5
\\{pool\_pointer};\C{the starting pointers}\2\6
\4\\{pool\_ptr}: \37\\{pool\_pointer};\C{first unused position in \\{str%
\_pool}}\6
\4\\{str\_ptr}: \37\\{str\_number};\C{start of the current string being
created}\6
\4\\{init\_pool\_ptr}: \37\\{pool\_pointer};\C{the starting value of \\{pool%
\_ptr}}\6
\4\\{init\_str\_ptr}: \37\\{str\_number};\C{the starting value of \\{str\_ptr}}%
\par
\fi

\M40. Several of the elementary string operations are performed using \.{WEB}
macros instead of using \PASCAL\ procedures, because many of the
operations are done quite frequently and we want to avoid the
overhead of procedure calls. For example, here is
a simple macro that computes the length of a string.

\Y\P\D \37$\\{length}(\#)\S(\\{str\_start}[\#+1]-\\{str\_start}[\#])$\C{the
number of characters 	in string number \#}\par
\fi

\M41. The length of the current string is called \\{cur\_length}:

\Y\P\D \37$\\{cur\_length}\S(\\{pool\_ptr}-\\{str\_start}[\\{str\_ptr}])$\par
\fi

\M42. Strings are created by appending character codes to \\{str\_pool}.
The macro called \\{append\_char}, defined here, does not check to see if the
value of \\{pool\_ptr} has gotten too high; this test is supposed to be
made before \\{append\_char} is used. There is also a \\{flush\_char}
macro, which erases the last character appended.

To test if there is room to append \|l more characters to \\{str\_pool},
we shall write $\\{str\_room}(\|l)$, which aborts \MF\ and gives an
apologetic error message if there isn't enough room.

\Y\P\D \37$\\{append\_char}(\#)\S$\C{put \\{ASCII\_code} \# at the end of %
\\{str\_pool}}\6
\&{begin} \37$\\{str\_pool}[\\{pool\_ptr}]\K\#$;\5
$\\{incr}(\\{pool\_ptr})$;\6
\&{end}\par
\P\D \37$\\{flush\_char}\S\\{decr}(\\{pool\_ptr})$\C{forget the last character
in the pool}\par
\P\D \37$\\{str\_room}(\#)\S$\C{make sure that the pool hasn't overflowed}\6
\&{begin} \37\&{if} $\\{pool\_ptr}+\#>\\{pool\_size}$ \1\&{then}\5
$\\{overflow}(\.{"pool\ size"},\39\\{pool\_size}-\\{init\_pool\_ptr})$;\2\6
\&{end}\par
\fi

\M43. Once a sequence of characters has been appended to \\{str\_pool}, it
officially becomes a string when the function \\{make\_string} is called.
This function returns the identification number of the new string as its
value.

\Y\P\4\&{function}\1\  \37\\{make\_string}: \37\\{str\_number};\C{current
string enters the pool}\2\6
\&{begin} \37\&{if} $\\{str\_ptr}=\\{max\_strings}$ \1\&{then}\5
$\\{overflow}(\.{"number\ of\ strings"},\39\\{max\_strings}-\\{init\_str%
\_ptr})$;\2\6
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{pool\_ptr}$;\5
$\\{make\_string}\K\\{str\_ptr}-1$;\6
\&{end};\par
\fi

\M44. To destroy the most recently made string, we say \\{flush\_string}.

\Y\P\D \37$\\{flush\_string}\S$\1\6
\&{begin} \37$\\{decr}(\\{str\_ptr})$;\5
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\6
\&{end}\2\par
\fi

\M45. The following subroutine compares string \|s with another string of the
same length that appears in \\{buffer} starting at position \|k;
the result is \\{true} if and only if the strings are equal.

\Y\P\4\&{function}\1\  \37$\\{str\_eq\_buf}(\|s:\\{str\_number};\,\35\|k:%
\\{integer})$: \37\\{boolean};\C{test equality of strings}\6
\4\&{label} \37\\{not\_found};\C{loop exit}\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{running index}\6
\\{result}: \37\\{boolean};\C{result of comparison}\2\6
\&{begin} \37$\|j\K\\{str\_start}[\|s]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37\&{if} $\\{str\_pool}[\|j]\I\\{buffer}[\|k]$ \1\&{then}\6
\&{begin} \37$\\{result}\K\\{false}$;\5
\&{goto} \37\\{not\_found};\6
\&{end};\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{result}\K\\{true}$;\6
\4\\{not\_found}: \37$\\{str\_eq\_buf}\K\\{result}$;\6
\&{end};\par
\fi

\M46. Here is a similar routine, but it compares two strings in the string
pool,
and it does not assume that they have the same length.

\Y\P\4\&{function}\1\  \37$\\{str\_eq\_str}(\|s,\39\|t:\\{str\_number})$: \37%
\\{boolean};\C{test equality of strings}\6
\4\&{label} \37\\{not\_found};\C{loop exit}\6
\4\&{var} \37$\|j,\39\|k$: \37\\{pool\_pointer};\C{running indices}\6
\\{result}: \37\\{boolean};\C{result of comparison}\2\6
\&{begin} \37$\\{result}\K\\{false}$;\6
\&{if} $\\{length}(\|s)\I\\{length}(\|t)$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|j\K\\{str\_start}[\|s]$;\5
$\|k\K\\{str\_start}[\|t]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37\&{if} $\\{str\_pool}[\|j]\I\\{str\_pool}[\|k]$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{result}\K\\{true}$;\6
\4\\{not\_found}: \37$\\{str\_eq\_str}\K\\{result}$;\6
\&{end};\par
\fi

\M47. The initial values of \\{str\_pool}, \\{str\_start}, \\{pool\_ptr},
and \\{str\_ptr} are computed by the \.{INIMF} program, based in part
on the information that \.{WEB} has output while processing \MF.

\Y\P\&{init} \37\&{function}\1\  \37\\{get\_strings\_started}: \37\\{boolean};%
\C{initializes the string pool, 	but returns \\{false} if something goes wrong}%
\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37$\|k,\39\|l$: \37$0\to127$;\C{small indices or counters}\6
$\|m,\39\|n$: \37\\{text\_char};\C{characters input from \\{pool\_file}}\6
\|g: \37\\{str\_number};\C{garbage}\6
\|a: \37\\{integer};\C{accumulator for check sum}\6
\|c: \37\\{boolean};\C{check sum has checked}\2\6
\&{begin} \37$\\{pool\_ptr}\K0$;\5
$\\{str\_ptr}\K0$;\5
$\\{str\_start}[0]\K0$;\5
\X48:Make the first 128 strings\X;\6
\X51:Read the other strings from the \.{MF.POOL} file and return \\{true}, or
give an error message and return \\{false}\X;\6
\4\\{exit}: \37\&{end};\6
\&{tini}\par
\fi

\M48. \P$\X48:Make the first 128 strings\X\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}127$ \1\&{do}\6
\&{begin} \37\&{if} $(\X49:Character \|k cannot be printed\X)$ \1\&{then}\6
\&{begin} \37$\\{append\_char}(\.{"\↑"})$;\5
$\\{append\_char}(\.{"\↑"})$;\6
\&{if} $\|k<\O{100}$ \1\&{then}\5
$\\{append\_char}(\|k+\O{100})$\6
\4\&{else} $\\{append\_char}(\|k-\O{100})$;\2\6
\&{end}\6
\4\&{else} $\\{append\_char}(\|k)$;\2\6
$\|g\K\\{make\_string}$;\6
\&{end}\2\par
\U section~47.\fi

\M49. The first 128 strings will contain 95 standard ASCII characters, and the
other 33 characters will be printed in three-symbol form like `\.{\↑\↑A}'
unless a system-dependent change is made here. Installations that have
an extended character set, where for example $\\{xchr}[\O{32}]=\hbox{\.{\'↑↑Z%
\'}}$,
would like string \O{32} to be the single character \O{32} instead of the
three characters \O{136}, \O{136}, \O{132} (\.{\↑\↑Z}). On the other hand,
even people with an extended character set will want to represent string
\O{15} by \.{\↑\↑M}, since \O{15} is \\{carriage\_return}; the idea is to
produce visible strings instead of tabs or line-feeds or carriage-returns
or bell-rings or characters that are treated anomalously in text files.

The boolean expression defined here should be \\{true} unless \MF\ internal
code number~\|k corresponds to a non-troublesome visible symbol in the
local character set.  At MIT, for example, the appropriate formula would
be `$\|k\in[0,\O{10}\to\O{12},\O{14},\O{15},\O{33},\O{177}]$'.  If character %
\|k cannot be
printed, then character $\|k+\O{100}$ or $\|k-\O{100}$ must be printable; thus,
at
least 64 printable characters are needed.

\Y\P$\4\X49:Character \|k cannot be printed\X\S$\6
$(\|k<\.{"\ "})\V(\|k>\.{"\~"})$\par
\U section~48.\fi

\M50. When the \.{WEB} system program called \.{TANGLE} processes the %
\.{MF.WEB}
description that you are now reading, it outputs the \PASCAL\ program
\.{MF.PAS} and also a string pool file called \.{MF.POOL}. The \.{INIMF}
program reads the latter file, where each string appears as a two-digit decimal
length followed by the string itself, and the information is recorded in
\MF's string memory.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{pool\_file}: \37\\{alpha\_file};\C{the string-pool file output
by \.{TANGLE}}\6
\&{tini}\par
\fi

\M51. \P\D \37$\\{bad\_pool}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{write\_ln}(\\{term\_out},\39\#)$;\5
$\\{a\_close}(\\{pool\_file})$;\5
$\\{get\_strings\_started}\K\\{false}$;\5
\&{return};\6
\&{end}\2\par
\Y\P$\4\X51:Read the other strings from the \.{MF.POOL} file and return %
\\{true}, or give an error message and return \\{false}\X\S$\6
$\\{name\_of\_file}\K\\{pool\_name}$;\C{we needn't set \\{name\_length}}\6
\&{if} $\\{a\_open\_in}(\\{pool\_file})$ \1\&{then}\6
\&{begin} \37$\|c\K\\{false}$;\6
\1\&{repeat} \37\X52:Read one string, but return \\{false} if the string memory
space is getting too tight for comfort\X;\6
\4\&{until}\5
\|c;\2\6
$\\{a\_close}(\\{pool\_file})$;\5
$\\{get\_strings\_started}\K\\{true}$;\6
\&{end}\6
\4\&{else} $\\{bad\_pool}(\.{\'!\ I\ can\'}\.{\'t\ read\ MF.POOL.\'})$\2\par
\U section~47.\fi

\M52. \P$\X52:Read one string, but return \\{false} if the string memory space
is getting too tight for comfort\X\S$\6
\&{begin} \37\&{if} $\\{eof}(\\{pool\_file})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ MF.POOL\ has\ no\ check\ sum.\'})$;\2\6
$\\{read}(\\{pool\_file},\39\|m,\39\|n)$;\C{read two digits of string length}\6
\&{if} $\|m=\.{\'*\'}$ \1\&{then}\5
\X53:Check the pool check sum\X\6
\4\&{else} \&{begin} \37\&{if} $(\\{xord}[\|m]<\.{"0"})\V(\\{xord}[\|m]>%
\.{"9"})\V\30(\\{xord}[\|n]<\.{"0"})\V(\\{xord}[\|n]>\.{"9"})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ MF.POOL\ line\ doesn\'}\.{\'t\ begin\ with\ two\ digits.%
\'})$;\2\6
$\|l\K\\{xord}[\|m]\ast10+\\{xord}[\|n]-\.{"0"}\ast11$;\C{compute the length}\6
\&{if} $\\{pool\_ptr}+\|l+\\{string\_vacancies}>\\{pool\_size}$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ You\ have\ to\ increase\ POOLSIZE.\'})$;\2\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\6
\&{begin} \37\&{if} $\\{eoln}(\\{pool\_file})$ \1\&{then}\5
$\|m\K\.{\'\ \'}$\ \&{else} $\\{read}(\\{pool\_file},\39\|m)$;\2\6
$\\{append\_char}(\\{xord}[\|m])$;\6
\&{end};\2\6
$\\{read\_ln}(\\{pool\_file})$;\5
$\|g\K\\{make\_string}$;\6
\&{end};\2\6
\&{end}\par
\U section~51.\fi

\M53. The \.{WEB} operation \.{@\$} denotes the value that should be at the
end of this \.{MF.POOL} file; any other value means that the wrong pool
file has been loaded.

\Y\P$\4\X53:Check the pool check sum\X\S$\6
\&{begin} \37$\|a\K0$;\5
$\|k\K1$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $(\\{xord}[\|n]<\.{"0"})\V(\\{xord}[\|n]>%
\.{"9"})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ MF.POOL\ check\ sum\ doesn\'}\.{\'t\ have\ nine\ digits.%
\'})$;\2\6
$\|a\K10\ast\|a+\\{xord}[\|n]-\.{"0"}$;\6
\&{if} $\|k=9$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\|k)$;\5
$\\{read}(\\{pool\_file},\39\|n)$;\6
\&{end};\2\6
\4\\{done}: \37\&{if} $\|a\I\)$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ MF.POOL\ doesn\'}\.{\'t\ match;\ TANGLE\ me\ again.%
\'})$;\2\6
$\|c\K\\{true}$;\6
\&{end}\par
\U section~52.\fi

\N54.  \[5] On-line and off-line printing.
Messages that are sent to a user's terminal and to the transcript-log file
are produced by several `\\{print}' procedures. These procedures will
direct their output to a variety of places, based on the setting of
the global variable \\{selector}, which has the following possible
values:

\yskip
\hang \\{term\_and\_log}, the normal setting, prints on the terminal and on the
transcript file.

\hang \\{log\_only}, prints only on the transcript file.

\hang \\{term\_only}, prints only on the terminal.

\hang \\{no\_print}, doesn't print at all. This is used only in rare cases
before the transcript file is open.

\hang \\{pseudo}, puts output into a cyclic buffer that is used
by the \\{show\_context} routine; see that routine for the
reasoning behind this curious mode.

\hang \\{new\_string}, appends the output to the current string in the
string pool.

\yskip
\noindent The symbolic names `\\{term\_and\_log}', etc., have been assigned
numeric codes that satisfy the convenient relations $\\{no\_print}+1=\\{term%
\_only}$,
$\\{no\_print}+2=\\{log\_only}$, $\\{term\_only}+2=\\{log\_only}+1=\\{term\_and%
\_log}$.

Three additional global variables, \\{tally} and \\{term\_offset} and
\\{file\_offset}, record the number of characters that have been printed
since they were most recently cleared to zero. We use \\{tally} to record
the length of (possibly very long) stretches of printing; \\{term\_offset}
and \\{file\_offset}, on the other hand, keep track of how many characters
have appeared so far on the current line that has been output to the
terminal or to the transcript file, respectively.

\Y\P\D \37$\\{no\_print}=0$\C{\\{selector} setting that makes data disappear}%
\par
\P\D \37$\\{term\_only}=1$\C{printing is destined for the terminal only}\par
\P\D \37$\\{log\_only}=2$\C{printing is destined for the transcript file only}%
\par
\P\D \37$\\{term\_and\_log}=3$\C{normal \\{selector} setting}\par
\P\D \37$\\{pseudo}=4$\C{special \\{selector} setting for \\{show\_context}}\par
\P\D \37$\\{new\_string}=5$\C{printing is deflected to the string pool}\par
\P\D \37$\\{max\_selector}=5$\C{highest selector setting}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{log\_file}: \37\\{alpha\_file};\C{transcript of \MF\ session}\6
\4\\{selector}: \37$0\to\\{max\_selector}$;\C{where to print a message}\6
\4\\{dig}: \37\&{array} $[0\to22]$ \1\&{of}\5
$0\to15$;\C{digits in a number being output}\2\6
\4\\{tally}: \37\\{integer};\C{the number of characters recently printed}\6
\4\\{term\_offset}: \37$0\to\\{max\_print\_line}$;\C{the number of characters
on the current terminal line}\6
\4\\{file\_offset}: \37$0\to\\{max\_print\_line}$;\C{the number of characters
on the current file line}\6
\4\\{trick\_buf}: \37\&{array} $[0\to\\{error\_line}]$ \1\&{of}\5
\\{ASCII\_code};\C{circular buffer for 	pseudoprinting}\2\6
\4\\{trick\_count}: \37\\{integer};\C{threshold for pseudoprinting, explained
later}\6
\4\\{first\_count}: \37\\{integer};\C{another variable for pseudoprinting}\par
\fi

\M55. \P$\X55:Initialize the output routines\X\S$\6
$\\{selector}\K\\{term\_only}$;\5
$\\{tally}\K0$;\5
$\\{term\_offset}\K0$;\5
$\\{file\_offset}\K0$;\par
\A sections~60, 618, and~623.
\U section~811.\fi

\M56. Macro abbreviations for output to the terminal and to the log file are
defined here for convenience. Some systems need special conventions
for terminal output, and it is possible to adhere to those conventions
by changing \\{wterm}, \\{wterm\_ln}, and \\{wterm\_cr} here.

\Y\P\D \37$\\{wterm}(\#)\S\\{write}(\\{term\_out},\39\#)$\par
\P\D \37$\\{wterm\_ln}(\#)\S\\{write\_ln}(\\{term\_out},\39\#)$\par
\P\D \37$\\{wterm\_cr}\S\\{write\_ln}(\\{term\_out})$\par
\P\D \37$\\{wlog}(\#)\S\\{write}(\\{log\_file},\39\#)$\par
\P\D \37$\\{wlog\_ln}(\#)\S\\{write\_ln}(\\{log\_file},\39\#)$\par
\P\D \37$\\{wlog\_cr}\S\\{write\_ln}(\\{log\_file})$\par
\fi

\M57. To end a line of text output, we call \\{print\_ln}.

\Y\P$\4\X57:Basic printing procedures\X\S$\6
\4\&{procedure}\1\  \37\\{print\_ln};\C{prints an end-of-line}\2\6
\&{begin} \37\&{case} $\\{selector}$ \1\&{of}\6
\4\\{term\_and\_log}: \37\&{begin} \37\\{wterm\_cr};\5
\\{wlog\_cr};\5
$\\{term\_offset}\K0$;\5
$\\{file\_offset}\K0$;\6
\&{end};\6
\4\\{log\_only}: \37\&{begin} \37\\{wlog\_cr};\5
$\\{file\_offset}\K0$;\6
\&{end};\6
\4\\{term\_only}: \37\&{begin} \37\\{wterm\_cr};\5
$\\{term\_offset}\K0$;\6
\&{end};\6
\4$\\{no\_print},\39\\{pseudo},\39\\{new\_string}$: \37\\{do\_nothing};\2\6
\&{end};\C{there are no other cases}\6
\&{end};\C{note that \\{tally} is not affected}\par
\A sections~58, 59, 61, 62, 63, and~608.
\U section~4.\fi

\M58. The \\{print\_char} procedure sends one character to the desired
destination,
using the \\{xchr} array to map it into an external character compatible with
\\{input\_ln}. All printing comes through \\{print\_ln} or \\{print\_char}.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_char}(\|s:\\{ASCII\_code})$;\C{prints a
single character}\2\6
\&{begin} \37\&{case} $\\{selector}$ \1\&{of}\6
\4\\{term\_and\_log}: \37\&{begin} \37$\\{wterm}(\\{xchr}[\|s])$;\5
$\\{wlog}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{term\_offset})$;\5
$\\{incr}(\\{file\_offset})$;\6
\&{if} $\\{term\_offset}=\\{max\_print\_line}$ \1\&{then}\6
\&{begin} \37\\{wterm\_cr};\5
$\\{term\_offset}\K0$;\6
\&{end};\2\6
\&{if} $\\{file\_offset}=\\{max\_print\_line}$ \1\&{then}\6
\&{begin} \37\\{wlog\_cr};\5
$\\{file\_offset}\K0$;\6
\&{end};\2\6
\&{end};\6
\4\\{log\_only}: \37\&{begin} \37$\\{wlog}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{file\_offset})$;\6
\&{if} $\\{file\_offset}=\\{max\_print\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
\&{end};\6
\4\\{term\_only}: \37\&{begin} \37$\\{wterm}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{term\_offset})$;\6
\&{if} $\\{term\_offset}=\\{max\_print\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
\&{end};\6
\4\\{no\_print}: \37\\{do\_nothing};\6
\4\\{pseudo}: \37\&{if} $\\{tally}<\\{trick\_count}$ \1\&{then}\5
$\\{trick\_buf}[\\{tally}\mathbin{\&{mod}}\\{error\_line}]\K\|s$;\2\6
\4\\{new\_string}: \37\&{begin} \37\&{if} $\\{pool\_ptr}<\\{pool\_size}$ \1%
\&{then}\5
$\\{append\_char}(\|s)$;\2\6
\&{end};\C{drop characters if the string space is full}\2\6
\&{end};\C{there are no other cases}\6
$\\{incr}(\\{tally})$;\6
\&{end};\par
\fi

\M59. An entire string is output by calling \\{print}. Note that if we are
outputting
the single standard ASCII character \.c, we could call $\\{print}(\.{"c"})$,
since
$\.{"c"}=99$ is the number of a single-character string, as explained above.
But
$\\{print\_char}(\.{"c"})$ is quicker, so \MF\ goes directly to the \\{print%
\_char}
routine when it knows that this is safe. (The present implementation
assumes that it is always safe to print a visible ASCII character.)

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print}(\|s:\\{integer})$;\C{prints string \|s}\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{current character code position}\2\6
\&{begin} \37\&{if} $(\|s<0)\V(\|s\G\\{str\_ptr})$ \1\&{then}\5
$\|s\K\.{"???"}$\C{this can't happen}\2\6
$\|j\K\\{str\_start}[\|s]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\\{str\_pool}[\|j])$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M60. Here is the very first thing that \MF\ prints: a headline that identifies
the version number and base name. The \\{term\_offset} variable is temporarily
incorrect, but the discrepancy is not serious since we assume that the banner
and base identifier together will occupy at most \\{max\_print\_line}
character positions.

\Y\P$\4\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{wterm}(\\{banner})$;\6
\&{if} $\\{base\_ident}=0$ \1\&{then}\5
$\\{wterm\_ln}(\.{\'\ (no\ base\ preloaded)\'})$\6
\4\&{else} \&{begin} \37$\\{print}(\\{base\_ident})$;\5
\\{print\_ln};\6
\&{end};\2\par
\fi

\M61. The procedure \\{print\_nl} is like \\{print}, but it makes sure that the
string appears at the beginning of a new line.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_nl}(\|s:\\{str\_number})$;\C{prints string %
\|s at beginning of line}\2\6
\&{begin} \37\&{if} $((\\{term\_offset}>0)\W(\\{odd}(\\{selector})))\V\30((%
\\{file\_offset}>0)\W(\\{selector}\G\\{log\_only}))$ \1\&{then}\5
\\{print\_ln};\2\6
$\\{print}(\|s)$;\6
\&{end};\par
\fi

\M62. An array of digits is printed by \\{print\_the\_digs}.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_the\_digs}(\|k:\\{eight\_bits})$;\C{prints $%
\\{dig}[\|k-1]$$\,\ldots\,$$\\{dig}[0]$}\2\6
\&{begin} \37\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|k)$;\6
\&{if} $\\{dig}[\|k]<10$ \1\&{then}\5
$\\{print\_char}(\.{"0"}+\\{dig}[\|k])$\6
\4\&{else} $\\{print\_char}(\.{"A"}-10+\\{dig}[\|k])$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M63. The following procedure, which prints out the decimal representation of a
given integer \|n, has been written carefully so that it works properly
if $\|n=0$ or if $(-\|n)$ would cause overflow. It does not apply $\mathbin{%
\&{mod}}$ or $\mathbin{\&{div}}$
to negative arguments, since such operations are not implemented consistently
by all \PASCAL\ compilers.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_int}(\|n:\\{integer})$;\C{prints an integer
in decimal form}\6
\4\&{var} \37\|k: \37$0\to20$;\C{index to current digit; we assume that $%
\|n<10↑{20}$}\6
\|m: \37\\{nonnegative\_integer};\C{used to negate \|n in possibly dangerous
cases}\2\6
\&{begin} \37$\|k\K0$;\6
\&{if} $\|n<0$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"-"})$;\6
\&{if} $\|n>-100000000$ \1\&{then}\5
$\\{negate}(\|n)$\6
\4\&{else} \&{begin} \37$\|m\K-1-\|n$;\5
$\|n\K\|m\mathbin{\&{div}}10$;\5
$\|m\K(\|m\mathbin{\&{mod}}10)+1$;\5
$\|k\K1$;\6
\&{if} $\|m<10$ \1\&{then}\5
$\\{dig}[0]\K\|m$\6
\4\&{else} \&{begin} \37$\\{dig}[0]\K0$;\5
$\\{incr}(\|n)$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\1\&{repeat} \37$\\{dig}[\|k]\K\|n\mathbin{\&{mod}}10$;\5
$\|n\K\|n\mathbin{\&{div}}10$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|n=0$;\2\6
$\\{print\_the\_digs}(\|k)$;\6
\&{end};\par
\fi

\M64. \MF\ also makes use of a trivial procedure to print two digits. The
following subroutine is usually called with a parameter in the range $0\L\|n%
\L99$.

\Y\P\4\&{procedure}\1\  \37$\\{print\_dd}(\|n:\\{integer})$;\C{prints two least
significant digits}\2\6
\&{begin} \37$\\{print\_char}(\.{"0"}+((\\{abs}(\|n)\mathbin{\&{div}}10)%
\mathbin{\&{mod}}10))$;\5
$\\{print\_char}(\.{"0"}+(\\{abs}(\|n)\mathbin{\&{mod}}10))$;\6
\&{end};\par
\fi

\M65. Here is a procedure that asks the user to type a line of input,
assuming that the \\{selector} setting is either \\{term\_only} or \\{term\_and%
\_log}.
The input is placed into locations \\{first} through $\\{last}-1$ of the
\\{buffer} array, and echoed on the transcript file if appropriate.

This procedure is never called when $\\{interaction}<\\{scroll\_mode}$.

\Y\P\D \37$\\{prompt\_input}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{print}(\#)$;\5
\\{term\_input};\6
\&{end}\C{prints a string and gets a line of input}\2\par
\Y\P\4\&{procedure}\1\  \37\\{term\_input};\C{gets a line from the terminal}\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\2\6
\&{begin} \37\\{update\_terminal};\C{Now the user sees the prompt for sure}\6
\&{if} $\R\\{input\_ln}(\\{term\_in},\39\\{true})$ \1\&{then}\5
$\\{fatal\_error}(\.{"End\ of\ file\ on\ the\ terminal!"})$;\2\6
$\\{term\_offset}\K0$;\C{the user's line ended with \<\rm return>}\6
$\\{decr}(\\{selector})$;\C{prepare to echo the input}\6
\&{if} $\\{last}\I\\{first}$ \1\&{then}\6
\&{for} $\|k\K\\{first}\mathrel{\&{to}}\\{last}-1$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\2\6
\\{print\_ln};\5
$\\{buffer}[\\{last}]\K\.{"\%"}$;\5
$\\{incr}(\\{selector})$;\C{restore previous status}\6
\&{end};\par
\fi

\N66.  \[6] Reporting errors.
When something anomalous is detected, \MF\ typically does something like this:
$$\vbox{\halign{#\hfil\cr
$\\{print\_err}(\.{"Something\ anomalous\ has\ been\ detected"})$;\cr
$\\{help3}(\.{"This\ is\ the\ first\ line\ of\ my\ offer\ to\ help."})$\cr
$(\.{"This\ is\ the\ second\ line.\ I\'m\ trying\ to"})$\cr
$(\.{"explain\ the\ best\ way\ for\ you\ to\ proceed."})$;\cr
\\{error};\cr}}$$
A two-line help message would be given using \\{help2}, etc.; these informal
helps should use simple vocabulary that complements the words used in the
official error message that was printed. (Outside of the U.S.A., the help
messages should preferably be translated into the local vernacular. Each
line of help is at most 60 characters long, in the present implementation,
so that \\{max\_print\_line} will not be exceeded.)

The \\{print\_err} procedure supplies a `\.!' before the official message,
and makes sure that the terminal is awake if a stop is going to occur.
The \\{error} procedure supplies a `\..' after the official message, then it
shows the location of the error; and if $\\{interaction}=\\{error\_stop%
\_mode}$,
it also enters into a dialog with the user, during which time the help
message may be printed.

\fi

\M67. The global variable \\{interaction} has four settings, representing
increasing
amounts of user interaction:

\Y\P\D \37$\\{batch\_mode}=0$\C{omits all stops and omits terminal output}\par
\P\D \37$\\{nonstop\_mode}=1$\C{omits all stops}\par
\P\D \37$\\{scroll\_mode}=2$\C{omits error stops}\par
\P\D \37$\\{error\_stop\_mode}=3$\C{stops at every opportunity to interact}\par
\P\D \37$\\{print\_err}(\#)\S$\1\6
\&{begin} \37\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
$\\{print\_nl}(\.{"!\ "})$;\5
$\\{print}(\#)$;\6
\&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{interaction}: \37$\\{batch\_mode}\to\\{error\_stop\_mode}$;\C{current
level of interaction}\par
\fi

\M68. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{interaction}\K\\{error\_stop\_mode}$;\par
\fi

\M69. \MF\ is careful not to call \\{error} when the print \\{selector} setting
might be unusual. The only possible values of \\{selector} at the time of
error messages are

\yskip\hang\\{no\_print} (when $\\{interaction}=\\{batch\_mode}$
and \\{log\_file} not yet open);

\hang\\{term\_only} (when $\\{interaction}>\\{batch\_mode}$ and \\{log\_file}
not yet open);

\hang\\{log\_only} (when $\\{interaction}=\\{batch\_mode}$ and \\{log\_file} is
open);

\hang\\{term\_and\_log} (when $\\{interaction}>\\{batch\_mode}$ and \\{log%
\_file} is open).

\Y\P$\4\X69:Initialize the print \\{selector} based on \\{interaction}\X\S$\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{selector}\K\\{no\_print}$\ \&{else} $\\{selector}\K\\{term\_only}$\2\par
\U section~816.\fi

\M70. A global variable \\{deletions\_allowed} is set \\{false} if the \\{get%
\_next}
routine is active when \\{error} is called; this ensures that \\{get\_next}
will never be called recursively.

The global variable \\{history} records the worst level of error that
has been detected. It has four possible values: \\{spotless}, \\{warning%
\_issued},
\\{error\_message\_issued}, and \\{fatal\_error\_stop}.

Another global variable, \\{error\_count}, is increased by one when an
\\{error} occurs without an interactive dialog, and it is reset to zero at
the end of every statement.  If \\{error\_count} reaches 100, \MF\ decides
that there is no point in continuing further.

\Y\P\D \37$\\{spotless}=0$\C{\\{history} value when nothing has been amiss yet}%
\par
\P\D \37$\\{warning\_issued}=1$\C{\\{history} value when \\{begin\_diagnostic}
has been called}\par
\P\D \37$\\{error\_message\_issued}=2$\C{\\{history} value when \\{error} has
been called}\par
\P\D \37$\\{fatal\_error\_stop}=3$\C{\\{history} value when termination was
premature}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{deletions\_allowed}: \37\\{boolean};\C{is it safe for \\{error} to call %
\\{get\_next}?}\6
\4\\{history}: \37$\\{spotless}\to\\{fatal\_error\_stop}$;\C{has the source
input been clean so far?}\6
\4\\{error\_count}: \37$-1\to100$;\C{the number of scrolled errors since the
	last statement ended}\par
\fi

\M71. The value of \\{history} is initially \\{fatal\_error\_stop}, but it will
be changed to \\{spotless} if \MF\ survives the initialization process.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{deletions\_allowed}\K\\{true}$;\5
$\\{error\_count}\K0$;\C{\\{history} is initialized elsewhere}\par
\fi

\M72. Since errors can be detected almost anywhere in \MF, we want to declare
the
error procedures near the beginning of the program. But the error procedures
in turn use some other procedures, which need to be declared \\{forward}
before we get to \\{error} itself.

It is possible for \\{error} to be called recursively if some error arises
when \\{get\_next} is being used to delete a token, or if some fatal error
occurs while \MF\ is trying to fix a non-fatal one. But such recursion
is never more than one level deep.

\Y\P$\4\X72:Error handling procedures\X\S$\6
\4\&{procedure}\1\  \37\\{normalize\_selector};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{term\_input};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{show\_context};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{begin\_file\_reading};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{open\_log\_file};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{clear\_for\_error\_prompt};\5
\\{forward};\5
\hbox{\2}\6
\hbox{\4\hskip-\fontdimen2\font}\ \&{debug} \37\ \&{procedure}\1\  \37\\{debug%
\_help};\5
\\{forward};\ \&{gubed} \par
\A sections~75, 76, 86, 87, and~88.
\U section~4.\fi

\M73. Individual lines of help are recorded in the array \\{help\_line}, which
contains entries in positions $0\to(\\{help\_ptr}-1)$. They should be printed
in reverse order, i.e., with $\\{help\_line}[0]$ last.

\Y\P\D \37$\\{hlp1}(\#)\S\\{help\_line}[0]\K\#$;\ \&{end} \par
\P\D \37$\\{hlp2}(\#)\S\\{help\_line}[1]\K\#$;\5
\\{hlp1}\par
\P\D \37$\\{hlp3}(\#)\S\\{help\_line}[2]\K\#$;\5
\\{hlp2}\par
\P\D \37$\\{hlp4}(\#)\S\\{help\_line}[3]\K\#$;\5
\\{hlp3}\par
\P\D \37$\\{hlp5}(\#)\S\\{help\_line}[4]\K\#$;\5
\\{hlp4}\par
\P\D \37$\\{hlp6}(\#)\S\\{help\_line}[5]\K\#$;\5
\\{hlp5}\par
\P\D \37$\\{help0}\S\\{help\_ptr}\K0$\C{sometimes there might be no help}\par
\P\D \37$\\{help1}\S$\ \&{begin} \37$\\{help\_ptr}\K1$;\5
\\{hlp1}\C{use this with one help line}\par
\P\D \37$\\{help2}\S$\ \&{begin} \37$\\{help\_ptr}\K2$;\5
\\{hlp2}\C{use this with two help lines}\par
\P\D \37$\\{help3}\S$\ \&{begin} \37$\\{help\_ptr}\K3$;\5
\\{hlp3}\C{use this with three help lines}\par
\P\D \37$\\{help4}\S$\ \&{begin} \37$\\{help\_ptr}\K4$;\5
\\{hlp4}\C{use this with four help lines}\par
\P\D \37$\\{help5}\S$\ \&{begin} \37$\\{help\_ptr}\K5$;\5
\\{hlp5}\C{use this with five help lines}\par
\P\D \37$\\{help6}\S$\ \&{begin} \37$\\{help\_ptr}\K6$;\5
\\{hlp6}\C{use this with six help lines}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{help\_line}: \37\&{array} $[0\to5]$ \1\&{of}\5
\\{str\_number};\C{helps for the next \\{error}}\2\6
\4\\{help\_ptr}: \37$0\to6$;\C{the number of help lines present}\6
\4\\{use\_err\_help}: \37\\{boolean};\C{should the \\{err\_help} list be
shown?}\par
\fi

\M74. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{help\_ptr}\K0$;\5
$\\{use\_err\_help}\K\\{false}$;\par
\fi

\M75. The \\{jump\_out} procedure just cuts across all active procedure levels
and
goes to \\{end\_of\_MF}. This is the only nonlocal \&{goto}  statement in the
whole program. It is used when there is no recovery from a particular error.

Some \PASCAL\ compilers do not implement non-local \&{goto}  statements.
In such cases the body of \\{jump\_out} should simply be
`\\{close\_files\_and\_terminate};' followed by a call on some system procedure
that quietly terminates the program.

\Y\P$\4\X72:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{jump\_out};\2\6
\&{begin} \37\&{goto} \37\\{end\_of\_MF};\6
\&{end};\par
\fi

\M76. Here now is the general \\{error} routine.

\Y\P$\4\X72:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{error};\C{completes the job of error reporting}\6
\4\&{label} \37$\\{continue},\39\\{exit}$;\6
\4\&{var} \37\|c: \37\\{ASCII\_code};\C{what the user types}\6
$\\{s1},\39\\{s2},\39\\{s3}$: \37\\{integer};\C{used to save global variables
when deleting tokens}\2\6
\&{begin} \37\&{if} $\\{history}<\\{error\_message\_issued}$ \1\&{then}\5
$\\{history}\K\\{error\_message\_issued}$;\2\6
$\\{print\_char}(\.{"."})$;\5
\\{show\_context};\6
\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\X77:Get user's advice and \&{return}\X;\2\6
$\\{incr}(\\{error\_count})$;\6
\&{if} $\\{error\_count}=100$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"(That\ makes\ 100\ errors;\ please\ try\
again.)"})$;\5
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\6
\&{end};\2\6
\X84:Put help message on the transcript file\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M77. \P$\X77:Get user's advice and \&{return}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37\\{clear\_for\_error\_prompt};\5
$\\{prompt\_input}(\.{"?\ "})$;\6
\&{if} $\\{last}=\\{first}$ \1\&{then}\5
\&{return};\2\6
$\|c\K\\{buffer}[\\{first}]$;\6
\&{if} $\|c\G\.{"a"}$ \1\&{then}\5
$\|c\K\|c+\.{"A"}-\.{"a"}$;\C{convert to uppercase}\2\6
\X78:Interpret code \|c and \&{return} if done\X;\6
\&{end}\2\par
\U section~76.\fi

\M78. It is desirable to provide an `\.E' option here that gives the user
an easy way to return from \MF\ to the system editor, with the offending
line ready to be edited. But such an extension requires some system
wizardry, so the present implementation simply types out what file should be
edited and the relevant line number.

There is a secret `\.D' option available when the debugging routines have
not been commented out.

\Y\P$\4\X78:Interpret code \|c and \&{return} if done\X\S$\6
\&{case} $\|c$ \1\&{of}\6
\4$\.{"1"},\39\.{"2"},\39\.{"3"},\39\.{"4"},\39\.{"5"},\39\.{"6"},\39\.{"7"},%
\39\.{"8"},\39\.{"9"}$: \37\&{if} $\\{deletions\_allowed}$ \1\&{then}\5
\X82:Delete $\|c-\.{"0"}$ tokens, \&{goto} \\{continue}\X;\2\6
\hbox{\4\4}\ \&{debug} \37\.{"D"}: \37\&{begin} \37\\{debug\_help};\5
\&{goto} \37\\{continue};\ \&{end};\ \&{gubed}\6
\4\.{"E"}: \37\&{if} $\\{base\_ptr}>0$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"You\ want\ to\ edit\ file\ "})$;\5
$\\{print}(\\{input\_stack}[\\{base\_ptr}].\\{name\_field})$;\5
$\\{print}(\.{"\ at\ line\ "})$;\5
$\\{print\_int}(\\{line})$;\5
$\\{interaction}\K\\{scroll\_mode}$;\5
\\{jump\_out};\6
\&{end};\2\6
\4\.{"H"}: \37\X83:Print the help information, \&{goto} \\{continue}\X;\6
\4\.{"I"}: \37\X81:Introduce new material from the terminal and \&{return}\X;\6
\4$\.{"Q"},\39\.{"R"},\39\.{"S"}$: \37\X80:Change the interaction level and %
\&{return}\X;\6
\4\.{"X"}: \37\&{begin} \37$\\{interaction}\K\\{scroll\_mode}$;\5
\\{jump\_out};\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\X79:Print the menu of available options\X\par
\U section~77.\fi

\M79. \P$\X79:Print the menu of available options\X\S$\6
$\\{print}(\.{"Type\ <return>\ to\ proceed,\ S\ to\ scroll\ future\ error\
messages,"})$;\6
$\\{print\_nl}(\.{"R\ to\ run\ without\ stopping,\ Q\ to\ run\ quietly,"})$;\6
$\\{print\_nl}(\.{"I\ to\ insert\ something,\ "})$;\6
\&{if} $\\{base\_ptr}>0$ \1\&{then}\5
$\\{print}(\.{"E\ to\ edit\ your\ file,"})$;\2\6
\&{if} $\\{deletions\_allowed}$ \1\&{then}\5
$\\{print\_nl}(\.{"1\ or\ ...\ or\ 9\ to\ ignore\ the\ next\ 1\ to\ 9\ tokens\
of\ input,"})$;\2\6
$\\{print\_nl}(\.{"H\ for\ help,\ X\ to\ quit."})$\par
\U section~78.\fi

\M80. Here the author of \MF\ apologizes for making use of the numerical
relation between \.{"Q"}, \.{"R"}, \.{"S"}, and the desired interaction
settings
\\{batch\_mode}, \\{nonstop\_mode}, \\{scroll\_mode}.

\Y\P$\4\X80:Change the interaction level and \&{return}\X\S$\6
\&{begin} \37$\\{error\_count}\K0$;\5
$\\{interaction}\K\\{batch\_mode}+\|c-\.{"Q"}$;\5
$\\{print}(\.{"OK,\ entering\ "})$;\6
\&{case} $\|c$ \1\&{of}\6
\4\.{"Q"}: \37\&{begin} \37$\\{print}(\.{"batchmode"})$;\5
$\\{decr}(\\{selector})$;\6
\&{end};\6
\4\.{"R"}: \37$\\{print}(\.{"nonstopmode"})$;\6
\4\.{"S"}: \37$\\{print}(\.{"scrollmode"})$;\2\6
\&{end};\C{there are no other cases}\6
$\\{print}(\.{"..."})$;\5
\\{print\_ln};\5
\\{update\_terminal};\5
\&{return};\6
\&{end}\par
\U section~78.\fi

\M81. When the following code is executed, $\\{buffer}[(\\{first}+1)\to(%
\\{last}-1)]$ may
contain the material inserted by the user; otherwise another prompt will
be given. In order to understand this part of the program fully, you need
to be familiar with \MF's input stacks.

\Y\P$\4\X81:Introduce new material from the terminal and \&{return}\X\S$\6
\&{begin} \37\\{begin\_file\_reading};\C{enter a new syntactic level for
terminal input}\6
\C{now $\\{state}=\\{mid\_line}$, so an initial blank space will count as a
blank}\6
\&{if} $\\{last}>\\{first}+1$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\\{first}+1$;\5
$\\{buffer}[\\{first}]\K\.{"\ "}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{prompt\_input}(\.{"insert>"})$;\5
$\\{loc}\K\\{first}$;\6
\&{end};\2\6
$\\{first}\K\\{last}+1$;\5
$\\{cur\_input}.\\{limit\_field}\K\\{last}$;\5
\&{return};\6
\&{end}\par
\U section~78.\fi

\M82. We allow deletion of up to 99 tokens at a time.

\Y\P$\4\X82:Delete $\|c-\.{"0"}$ tokens, \&{goto} \\{continue}\X\S$\6
\&{begin} \37$\\{s1}\K\\{cur\_cmd}$;\5
$\\{s2}\K\\{cur\_mod}$;\5
$\\{s3}\K\\{cur\_sym}$;\5
$\\{OK\_to\_interrupt}\K\\{false}$;\6
\&{if} $(\\{last}>\\{first}+1)\W(\\{buffer}[\\{first}+1]\G\.{"0"})\W(%
\\{buffer}[\\{first}+1]\L\.{"9"})$ \1\&{then}\5
$\|c\K\|c\ast10+\\{buffer}[\\{first}+1]-\.{"0"}\ast11$\6
\4\&{else} $\|c\K\|c-\.{"0"}$;\2\6
\&{while} $\|c>0$ \1\&{do}\6
\&{begin} \37\\{get\_next};\C{one-level recursive call of \\{error} is
possible}\6
$\\{decr}(\|c)$;\6
\&{end};\2\6
$\\{cur\_cmd}\K\\{s1}$;\5
$\\{cur\_mod}\K\\{s2}$;\5
$\\{cur\_sym}\K\\{s3}$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
$\\{help2}(\.{"I\ have\ just\ deleted\ some\ text,\ as\ you\ asked."})$\6
$(\.{"You\ can\ now\ delete\ more,\ or\ insert,\ or\ whatever."})$;\5
\\{show\_context};\5
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~78.\fi

\M83. \P$\X83:Print the help information, \&{goto} \\{continue}\X\S$\6
\&{begin} \37\&{if} $\\{help\_ptr}=0$ \1\&{then}\5
$\\{help2}(\.{"Sorry,\ I\ don\'t\ know\ how\ to\ help\ in\ this\ situation."})$%
\2\6
$(\.{"Maybe\ you\ should\ try\ asking\ a\ human?"})$;\6
\1\&{repeat} \37$\\{decr}(\\{help\_ptr})$;\5
$\\{print}(\\{help\_line}[\\{help\_ptr}])$;\5
\\{print\_ln};\6
\4\&{until}\5
$\\{help\_ptr}=0$;\2\6
$\\{help4}(\.{"Sorry,\ I\ already\ gave\ what\ help\ I\ could..."})$\6
$(\.{"Maybe\ you\ should\ try\ asking\ a\ human?"})$\6
$(\.{"An\ error\ might\ have\ occurred\ before\ I\ noticed\ any\ problems."})$\6
$(\.{"\`\`If\ all\ else\ fails,\ read\ the\ instructions.\'\'"})$;\5
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~78.\fi

\M84. \P$\X84:Put help message on the transcript file\X\S$\6
\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
$\\{decr}(\\{selector})$;\C{avoid terminal output}\2\6
\&{if} $\\{use\_err\_help}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\\{give\_err\_help};\6
\&{end}\6
\4\&{else} \&{while} $\\{help\_ptr}>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{help\_ptr})$;\5
$\\{print\_nl}(\\{help\_line}[\\{help\_ptr}])$;\6
\&{end};\2\2\6
\\{print\_ln};\6
\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
$\\{incr}(\\{selector})$;\C{enable terminal output}\2\6
\\{print\_ln}\par
\U section~76.\fi

\M85. In anomalous cases, the print selector might be in an unknown state;
the following subroutine is called to fix things just enough to keep
running a bit longer.

\Y\P\4\&{procedure}\1\  \37\\{normalize\_selector};\2\6
\&{begin} \37\&{if} $\\{job\_name}>0$ \1\&{then}\5
$\\{selector}\K\\{term\_and\_log}$\6
\4\&{else} $\\{selector}\K\\{term\_only}$;\2\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{decr}(\\{selector})$;\2\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{end};\par
\fi

\M86. The following procedure prints \MF's last words before dying.

\Y\P\D \37$\\{succumb}\S$\1\6
\&{begin} \37\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
$\\{interaction}\K\\{scroll\_mode}$;\C{no more interaction}\2\6
\\{error};\6
\&{debug} \37\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
\\{debug\_help};\ \2\6
\&{gubed}\6
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\C{irrecoverable error}\6
\&{end}\2\par
\Y\P$\4\X72:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{fatal\_error}(\|s:\\{str\_number})$;\C{prints \|s,
and that's it}\2\6
\&{begin} \37\\{normalize\_selector};\6
$\\{print\_err}(\.{"Emergency\ stop"})$;\5
$\\{help1}(\|s)$;\5
\\{succumb};\6
\&{end};\par
\fi

\M87. Here is the most dreaded error message.

\Y\P$\4\X72:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{overflow}(\|s:\\{str\_number};\,\35\|n:%
\\{integer})$;\C{stop due to finiteness}\2\6
\&{begin} \37\\{normalize\_selector};\5
$\\{print\_err}(\.{"METAFONT\ capacity\ exceeded,\ sorry\ ["})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print\_char}(\.{"]"})$;\5
$\\{help2}(\.{"If\ you\ really\ absolutely\ need\ more\ capacity,"})$\6
$(\.{"you\ can\ ask\ a\ wizard\ to\ enlarge\ me."})$;\5
\\{succumb};\6
\&{end};\par
\fi

\M88. The program might sometime run completely amok, at which point there is
no choice but to stop. If no previous error has been detected, that's bad
news; a message is printed that is really intended for the \MF\
maintenance person instead of the user (unless the user has been
particularly diabolical).  The index entries for `this can't happen' may
help to pinpoint the problem.

\Y\P$\4\X72:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{confusion}(\|s:\\{str\_number})$;\C{consistency
check violated; \|s tells where}\2\6
\&{begin} \37\\{normalize\_selector};\6
\&{if} $\\{history}<\\{error\_message\_issued}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"This\ can\'t\ happen\ ("})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{")"})$;\5
$\\{help1}(\.{"I\'m\ broken.\ Please\ show\ this\ to\ someone\ who\ can\ fix\
can\ fix"})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"I\ can\'t\ go\ on\ meeting\ you\
like\ this"})$;\5
$\\{help2}(\.{"One\ of\ your\ earlier\ faux\ pas\ has\ wounded\ me\ deeply,"})$%
\6
$(\.{"so\ I\'m\ barely\ conscious.\ Please\ fix\ it\ and\ try\ again."})$;\6
\&{end};\2\6
\\{succumb};\6
\&{end};\par
\fi

\M89. Users occasionally want to interrupt \MF\ while it's running.
If the \PASCAL\ runtime system allows this, one can implement
a routine that sets the global variable \\{interrupt} to some nonzero value
when such an interrupt is signalled. Otherwise there is probably at least
a way to make \\{interrupt} nonzero using the \PASCAL\ debugger.

\Y\P\D \37$\\{check\_interrupt}\S$\1\6
\&{begin} \37\&{if} $\\{interrupt}\I0$ \1\&{then}\5
\\{pause\_for\_instructions};\2\6
\&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{interrupt}: \37\\{integer};\C{should \MF\ pause for instruction?}\6
\4\\{OK\_to\_interrupt}: \37\\{boolean};\C{should interrupts be observed?}\par
\fi

\M90. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{interrupt}\K0$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\par
\fi

\M91. When an interrupt has been detected, the program goes into its
highest interaction level and lets the user have the full flexibility of
the \\{error} routine.  \MF\ checks for interrupts only at times when it is
safe to do this.

\Y\P\4\&{procedure}\1\  \37\\{pause\_for\_instructions};\2\6
\&{begin} \37\&{if} $\\{OK\_to\_interrupt}$ \1\&{then}\6
\&{begin} \37$\\{interaction}\K\\{error\_stop\_mode}$;\6
\&{if} $(\\{selector}=\\{log\_only})\V(\\{selector}=\\{no\_print})$ \1\&{then}\5
$\\{incr}(\\{selector})$;\2\6
$\\{print\_err}(\.{"Interruption"})$;\5
$\\{help3}(\.{"You\ rang?"})$\6
$(\.{"Try\ to\ insert\ some\ instructions\ for\ me\ (e.g.,\`I\ showvar\ x%
\'),"})$\6
$(\.{"unless\ you\ just\ want\ to\ quit\ by\ typing\ \`X\'."})$;\5
$\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\5
$\\{interrupt}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\N92.  \[7] Arithmetic with scaled numbers.
The principal computations performed by \MF\ are done entirely in terms of
integers less than $2↑{31}$ in magnitude; thus, the arithmetic specified in
this
program can be carried out in exactly the same way on a wide variety of
computers, including some small ones.

But \PASCAL\ does not define the $\mathbin{\&{div}}$
operation in the case of negative dividends; for example, the result of
$(-2\ast\|n-1)\mathbin{\&{div}}2$ is $-\|n-1$ on some computers and $-\|n$ on
others.
There are two principal types of arithmetic: ``Translation-preserving,''
in which the identital $(\|a+\|q\ast\|b)\mathbin{\&{div}}\|b=(\|a\mathbin{%
\&{div}}\|b)+\|q$ is valid; and
``negation-preserving,'' in which $(-\|a)\mathbin{\&{div}}\|b=-(\|a\mathbin{%
\&{div}}\|b)$. This leads to
two \MF s, which can produce different results, although the differences
should be negligible when the language is being used properly.
The \TeX\ processor has been defined carefully so that both varieties
of arithmetic will produce identical output, but it would be too
inefficient to constrain \MF\ in a similar way.

\Y\P\D \37$\\{el\_gordo}\S\O{17777777777}$\C{$2↑{31}-1$, the largest value that
\MF\ likes}\par
\fi

\M93. One of \MF's most common operations is the calculation of
$\lfloor{a+b\over2}\rfloor$,
the midpoint of two given integers \|a and~\|b. The only decent way to do
this in \PASCAL\ is to write `$(\|a+\|b)\mathbin{\&{div}}2$'; but on most
machines it is
far more efficient to calculate `$(\|a+\|b)$ right shifted one bit'.

Therefore the midpoint operation will always be denoted by `$\\{half}(\|a+%
\|b)$'
in this program. If \MF\ is being implemented with languages that permit
binary shifting, the \\{half} macro should be changed to make this operation
as efficient as possible.

\Y\P\D \37$\\{half}(\#)\S(\#)\mathbin{\&{div}}2$\par
\fi

\M94. A single computation might use several subroutine calls, and it is
desirable to avoid producing multiple error messages in case of arithmetic
overflow. So the routines below set the global variable \\{arith\_error} to %
\\{true}
instead of reporting errors directly to the user.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{arith\_error}: \37\\{boolean};\C{has arithmetic overflow occurred
recently?}\par
\fi

\M95. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{arith\_error}\K\\{false}$;\par
\fi

\M96. At crucial points the program will say \\{check\_arith}, to test if
an arithmetic error has been detected.

\Y\P\D \37$\\{check\_arith}\S$\1\6
\&{begin} \37\&{if} $\\{arith\_error}$ \1\&{then}\5
\\{clear\_arith};\ \2\6
\&{end}\2\par
\Y\P\4\&{procedure}\1\  \37\\{clear\_arith};\2\6
\&{begin} \37$\\{print\_err}(\.{"Arithmetic\ overflow"})$;\5
$\\{help4}(\.{"Uh,\ oh.\ A\ little\ while\ ago\ one\ of\ the\ quantities\ that\
I\ was"})$\6
$(\.{"computing\ got\ too\ large,\ so\ I\'m\ afraid\ your\ answers\ will\
be"})$\6
$(\.{"somewhat\ askew.\ You\'ll\ probably\ have\ to\ adopt\ different"})$\6
$(\.{"tactics\ next\ time.\ But\ I\ shall\ try\ to\ carry\ on\ anyway."})$;\5
\\{error};\5
$\\{arith\_error}\K\\{false}$;\6
\&{end};\par
\fi

\M97. Fixed-point arithmetic is done on {\sl scaled integers\/} that are
multiples
of $2↑{-16}$. In other words, a binary point is assumed to be sixteen bit
positions from the right end of a binary computer word.

\Y\P\D \37$\\{quarter\_unit}\S\O{40000}$\C{$2↑{14}$, represents 0.250000}\par
\P\D \37$\\{half\_unit}\S\O{100000}$\C{$2↑{15}$, represents 0.50000}\par
\P\D \37$\\{three\_quarter\_unit}\S\O{140000}$\C{$3\cdot2↑{14}$, represents
0.750000}\par
\P\D \37$\\{unity}\S\O{200000}$\C{$2↑{16}$, represents 1.00000}\par
\P\D \37$\\{two}\S\O{400000}$\C{$2↑{17}$, represents 2.00000}\par
\P\D \37$\\{three}\S\O{600000}$\C{$2↑{17}+2↑{16}$, represents 3.00000}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{scaled}=\\{integer}$;\C{this type is used for scaled integers}\6
$\\{nonnegative\_integer}=0\to\\{el\_gordo}$;\C{$0\L x<2↑{31}$}\6
$\\{small\_number}=0\to63$;\C{this type is self-explanatory}\par
\fi

\M98. The following function is used to create a scaled integer from a decimal
fraction $(.d_0d_1\ldots d_{k-1})$, where $0\L\|k\L17$. The digit $d_i$ is
given in $\\{dig}[\|i]$, and the calculation produces a correctly rounded
result.

\Y\P\4\&{function}\1\  \37$\\{round\_decimals}(\|k:\\{small\_number})$: \37%
\\{scaled};\C{converts a decimal fraction}\6
\4\&{var} \37\|a: \37\\{integer};\C{the accumulator}\2\6
\&{begin} \37$\|a\K0$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|k)$;\5
$\|a\K(\|a+\\{dig}[\|k]\ast\\{two})\mathbin{\&{div}}10$;\6
\&{end};\2\6
$\\{round\_decimals}\K\\{half}(\|a+1)$;\6
\&{end};\par
\fi

\M99. Conversely, here is a procedure analogous to \\{print\_int}. If the
output
of this procedure is subsequently read by \MF\ and converted by the
\\{round\_decimals} routine above, it turns out that the original value will
be reproduced exactly. A decimal point is printed only if the value is
not an integer. If there is more than one way to print the result with
the optimum number of digits following the decimal point, the closest
possible value is given.

The invariant relation in the \&{repeat} loop is that a sequence of
decimal digits yet to be printed will yield the original number if and only if
they form a fraction~$f$ in the range $s-\delta\L10\cdot2↑{16}f<s$.
We can stop if and only if $f=0$ satisfies this condition; the loop will
terminate before $s$ can possibly become zero.

\Y\P\4\&{procedure}\1\  \37$\\{print\_scaled}(\|s:\\{scaled})$;\C{prints scaled
real, rounded to five 	digits}\6
\4\&{var} \37\\{delta}: \37\\{scaled};\C{amount of allowable inaccuracy}\2\6
\&{begin} \37\&{if} $\|s<0$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"-"})$;\5
$\\{negate}(\|s)$;\C{print the sign, if negative}\6
\&{end};\2\6
$\\{print\_int}(\|s\mathbin{\&{div}}\\{unity})$;\C{print the integer part}\6
$\|s\K10\ast(\|s\mathbin{\&{mod}}\\{unity})+5$;\6
\&{if} $\|s\I5$ \1\&{then}\6
\&{begin} \37$\\{delta}\K10$;\5
$\\{print\_char}(\.{"."})$;\6
\1\&{repeat} \37\&{if} $\\{delta}>\\{unity}$ \1\&{then}\5
$\|s\K\|s+\O{100000}-(\\{delta}\mathbin{\&{div}}2)$;\C{round the final digit}\2%
\6
$\\{print\_char}(\.{"0"}+(\|s\mathbin{\&{div}}\\{unity}))$;\5
$\|s\K10\ast(\|s\mathbin{\&{mod}}\\{unity})$;\5
$\\{delta}\K\\{delta}\ast10$;\6
\4\&{until}\5
$\|s\L\\{delta}$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M100. We often want to print two scaled quantities in parentheses,
separated by a comma.

\Y\P\4\&{procedure}\1\  \37$\\{print\_two}(\|x,\39\|y:\\{scaled})$;\C{prints `$%
\|x,\|y$'}\2\6
\&{begin} \37$\\{print\_char}(\.{"("})$;\5
$\\{print\_scaled}(\|x)$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\|y)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\par
\fi

\M101. The \\{scaled} quantities in \MF\ programs are generally supposed to be
less than $2↑{12}$ in absolute value, so \MF\ does much of its internal
arithmetic with 28~significant bits of precision. A \\{fraction} denotes
a scaled integer whose binary point is assumed to be 28 bit positions
from the right.

\Y\P\D \37$\\{fraction\_half}\S\O{1000000000}$\C{$2↑{27}$, represents
0.50000000}\par
\P\D \37$\\{fraction\_one}\S\O{2000000000}$\C{$2↑{28}$, represents 1.00000000}%
\par
\P\D \37$\\{fraction\_two}\S\O{4000000000}$\C{$2↑{29}$, represents 2.00000000}%
\par
\P\D \37$\\{fraction\_three}\S\O{6000000000}$\C{$3\cdot2↑{28}$, represents
3.00000000}\par
\P\D \37$\\{fraction\_four}\S\O{10000000000}$\C{$2↑{30}$, represents
4.00000000}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{fraction}=\\{integer}$;\C{this type is used for scaled fractions}\par
\fi

\M102. In fact, the two sorts of scaling aren't quite sufficient; \MF\ has yet
another, used internally to keep track of angles in units of $2↑{-20}$
degrees.

\Y\P\D \37$\\{forty\_five\_deg}\S\O{264000000}$\C{$45\cdot2↑{20}$, represents
$45↑\circ$}\par
\P\D \37$\\{ninety\_deg}\S\O{550000000}$\C{$90\cdot2↑{20}$, represents $90↑%
\circ$}\par
\P\D \37$\\{one\_eighty\_deg}\S\O{1320000000}$\C{$180\cdot2↑{20}$, represents
$180↑\circ$}\par
\P\D \37$\\{three\_sixty\_deg}\S\O{2640000000}$\C{$360\cdot2↑{20}$, represents
$360↑\circ$}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{angle}=\\{integer}$;\C{this type is used for scaled angles}\par
\fi

\M103. The \\{make\_fraction} routine produces the \\{fraction} equivalent of
$\|p/\|q$, given integers \|p and~\|q; it computes the integer
$f=\lfloor2↑{28}p/q+{1\over2}\rfloor$, when $p$ and $q$ are
positive. If \|p and \|q are both of
the same scaled type \|t, we have $\\{make\_fraction}(\|t,\|t)=\\{fraction}$;
and it's also possible to use the subroutine ``backwards,'' using
the relation $\\{make\_fraction}(\|t,\\{fraction})=\|t$ between scaled types.

If the result would have magnitude $2↑{31}$ or more, \\{make\_fraction}
sets $\\{arith\_error}\K\\{true}$. Most of \MF's internal computations have
been designed to avoid this sort of error.

If this subroutine were programmed in assembly language on a typical
machine, we could simply compute $(\hbox{$2↑{28}$}\ast\|p)\mathbin{\&{div}}%
\|q$, since a
double-precision product can often be input to a fixed-point division
instruction. But when we are restricted to \PASCAL\ arithmetic it
is necessary either to resort to multiple-precision maneuvering
or to use a simple but slow iteration. The multiple-precision technique
would be about three times faster than the code adopted here, but it
would be comparatively long and tricky, involving about sixteen
additional multiplications and divisions.

This operation is not part of \MF's ``inner loop,'' so it has been
implemented in a simple but slow way that avoids multiplication
and division except in the initial stage. Many of the routines that
follow could, similarly, be made to run about three times faster
at the cost of longer and trickier programs; but \MF\ as a whole
would not be speeded up by very much, so the author has opted for
simplicity and robustness.

\Y\P\4\&{function}\1\  \37$\\{make\_fraction}(\|p,\39\|q:\\{integer})$: \37%
\\{fraction};\6
\4\&{var} \37\|f: \37\\{integer};\C{the fraction bits, with a leading 1 bit}\6
\|n: \37\\{integer};\C{the integer part of $\vert p/q\vert$}\6
\\{negative}: \37\\{boolean};\C{should the result be negated?}\6
\\{be\_careful}: \37\\{integer};\C{disables certain compiler optimizations}\2\6
\&{begin} \37\&{if} $\|p\G0$ \1\&{then}\5
$\\{negative}\K\\{false}$\6
\4\&{else} \&{begin} \37$\\{negate}(\|p)$;\5
$\\{negative}\K\\{true}$;\6
\&{end};\2\6
\&{if} $\|q\L0$ \1\&{then}\6
\&{begin} \37\&{if} $\|q=0$ \1\&{then}\5
$\\{confusion}(\.{"fraction"})$;\2\6
$\\{negate}(\|q)$;\5
$\\{negative}\K\R\\{negative}$;\6
\&{end};\2\6
$\|n\K\|p\mathbin{\&{div}}\|q$;\5
$\|p\K\|p\mathbin{\&{mod}}\|q$;\6
\&{if} $\|n<8$ \1\&{then}\5
$\|n\K(\|n-1)\ast\\{fraction\_one}$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\O{14000000000}$;\C{6.00000000}\6
\&{end};\2\6
\X104:Compute $f=\lfloor 2↑{28}(1+p/q)+{1\over2}\rfloor$\X;\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{make\_fraction}\K-(\|f+\|n)$\6
\4\&{else} $\\{make\_fraction}\K\|f+\|n$;\2\6
\&{end};\par
\fi

\M104. The  \&{repeat}  loop here preserves the following invariant relations:
(i)~$0\L\|p<\|q$; (ii)~$fq+p=2↑k(q+p_0)$, where $k$ is an integer and
$p_0$ is the original value of~$p$.

Notice that the computation specifies
$(\|p-\|q)+\|p$ instead of $(\|p+\|p)-\|q$, because the latter could overflow.
Let us hope that optimizing compilers do not miss this point; a
special variable \\{be\_careful} is used to emphasize the necessary
order of computation. Optimizing compilers should keep \\{be\_careful}
in a register, not store it in memory.

\Y\P$\4\X104:Compute $f=\lfloor 2↑{28}(1+p/q)+{1\over2}\rfloor$\X\S$\6
$\|f\K1$;\6
\1\&{repeat} \37$\\{be\_careful}\K\|p-\|q$;\5
$\|p\K\\{be\_careful}+\|p$;\6
\&{if} $\|p\G0$ \1\&{then}\5
$\|f\K\|f+\|f+1$\6
\4\&{else} \&{begin} \37$\|f\K\|f+\|f$;\5
$\|p\K\|p+\|q$;\6
\&{end};\2\6
\4\&{until}\5
$\|f\G\\{fraction\_one}$;\2\6
$\\{be\_careful}\K\|p-\|q$;\6
\&{if} $\\{be\_careful}+\|p\G0$ \1\&{then}\5
$\\{incr}(\|f)$\2\par
\U section~103.\fi

\M105. The dual of \\{make\_fraction} is \\{take\_fraction}, which multiplies a
given integer~\|q by a fraction~\|f. When the operands are positive, it
computes $p=\lfloor qf/2↑{28}+{1\over2}\rfloor$, a symmetric function
of \|q and~\|f.

\Y\P\4\&{function}\1\  \37$\\{take\_fraction}(\|q:\\{integer};\,\35\|f:%
\\{fraction})$: \37\\{integer};\6
\4\&{var} \37\|p: \37\\{integer};\C{the fraction so far}\6
\\{negative}: \37\\{boolean};\C{should the result be negated?}\6
\|n: \37\\{integer};\C{additional multiple of $q$}\6
\\{be\_careful}: \37\\{integer};\C{disables certain compiler optimizations}\2\6
\&{begin} \37\X106:Reduce to the case that $\|f\G0$ and $\|q>0$\X;\6
\&{if} $\|f<\\{fraction\_one}$ \1\&{then}\5
$\|n\K0$\6
\4\&{else} \&{begin} \37$\|n\K\|f\mathbin{\&{div}}\\{fraction\_one}$;\5
$\|f\K\|f\mathbin{\&{mod}}\\{fraction\_one}$;\6
\&{if} $\|q\L\\{el\_gordo}\mathbin{\&{div}}\|n$ \1\&{then}\5
$\|n\K\|n\ast\|q$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\\{el\_gordo}-\|q$;\6
\&{end};\2\6
\&{end};\2\6
$\|f\K\|f+\\{fraction\_one}$;\5
\X107:Compute $p=\lfloor qf/2↑{28}+{1\over2}\rfloor-q$\X;\6
$\\{be\_careful}\K\|n-\\{el\_gordo}$;\6
\&{if} $\\{be\_careful}+\|p>0$ \1\&{then}\6
\&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\\{el\_gordo}-\|p$;\6
\&{end};\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{take\_fraction}\K-(\|n+\|p)$\6
\4\&{else} $\\{take\_fraction}\K\|n+\|p$;\2\6
\&{end};\par
\fi

\M106. \P$\X106:Reduce to the case that $\|f\G0$ and $\|q>0$\X\S$\6
\&{if} $\|f\G0$ \1\&{then}\5
$\\{negative}\K\\{false}$\6
\4\&{else} \&{begin} \37$\\{negate}(\|f)$;\5
$\\{negative}\K\\{true}$;\6
\&{end};\2\6
\&{if} $\|q<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|q)$;\5
$\\{negative}\K\R\\{negative}$;\6
\&{end};\2\par
\U sections~105 and~109.\fi

\M107. The invariant relations in this case are (i)~$\lfloor(qf+p)/2↑k\rfloor
=\lfloor qf_0/2↑{28}+{1\over2}\rfloor$, where $k$ is an integer and
$f_0$ is the original value of~$f$; (ii)~$2↑k\L f<2↑{k+1}$.

\Y\P$\4\X107:Compute $p=\lfloor qf/2↑{28}+{1\over2}\rfloor-q$\X\S$\6
$\|p\K\O{1000000000}$;\C{$2↑{27}$; the invariants hold now with $k=28$}\6
\1\&{repeat} \37\&{if} $\\{odd}(\|f)$ \1\&{then}\5
$\|p\K\\{half}(\|p+\|q)$\ \&{else} $\|p\K\\{half}(\|p)$;\2\6
$\|f\K\\{half}(\|f)$;\6
\4\&{until}\5
$\|f=1$\2\par
\U section~105.\fi

\M108. Here is an example of a typical use of the \\{fraction}-oriented
routines.
It computes the function
$${1\over3\tau}f(\theta,\phi)=
{\tau↑{-1}\bigl(2+\sqrt2(\sin\theta-{1\over16}\sin\phi)
(\sin\phi-{1\over16}\sin\theta)(cos\theta-\cos\phi)\bigr)\over
3\,\bigl(1+{1\over2}(\sqrt5-1)\cos\theta+{1\over2}(3-\sqrt5\,)\cos\phi%
\bigr)},$$
where $\tau$ is a \\{scaled} ``tension'' parameter. This is \MF's magic
fudge factor for placing the first control point of a curve that starts
at an angle $\theta$ and ends at an angle $\phi$ from the straight path.
(Actually, if the stated quantity exceeds 4, \MF\ reduces it to~4.)

The tension is at least $3\over4$, hence the numerator of the expression above
is less than ${4\over3}(2+\sqrt2\cdot{17\over16}\cdot{17\over16}\cdot2)<7$;
and the denominator is at most~6. Hence the fixed-point calculations below
are guaranteed to stay within the bounds of a 32-bit computer word.

The angles $\theta$ and $\phi$ are given implicitly in terms of \\{fraction}
arguments \\{st}, \\{ct}, \\{sf}, and \\{cf}, representing $\sin\theta$, $\cos%
\theta$,
$\sin\phi$, and $\cos\phi$, respectively.

\Y\P\4\&{function}\1\  \37$\\{velocity}(\\{st},\39\\{ct},\39\\{sf},\39\\{cf}:%
\\{fraction};\,\35\|t:\\{scaled})$: \37\\{fraction};\6
\4\&{var} \37$\\{acc},\39\\{num},\39\\{denom}$: \37\\{integer};\C{registers for
intermediate calculations}\2\6
\&{begin} \37$\\{acc}\K\\{take\_fraction}(\\{st}-(\\{sf}\mathbin{\&{div}}16),%
\39\\{sf}-(\\{st}\mathbin{\&{div}}16))$;\5
$\\{acc}\K\\{take\_fraction}(\\{acc},\39\\{ct}-\\{cf})$;\5
$\\{num}\K\\{fraction\_two}+\\{take\_fraction}(\\{acc},\39379625062)$;\C{that's
$2↑{28}\sqrt2$}\6
$\\{denom}\K\\{fraction\_three}+\\{take\_fraction}(\\{ct},\39497706707)+\\{take%
\_fraction}(\\{cf},\39307599661)$;\C{the constants are $3\cdot2↑{28}$ times
		$.618\ldots$ and $1-.618\ldots=(.618\ldots\,)↑2$}\6
\&{if} $\|t\I\\{unity}$ \1\&{then}\6
\&{if} $\|t\G\O{2000000}$ \1\&{then}\5
$\\{num}\K\\{take\_fraction}(\\{num}\mathbin{\&{div}}\O{10000},\39\|t)$\6
\4\&{else} $\\{num}\K\\{take\_fraction}(\\{num},\39\|t\ast\O{10000})$;\2\2\6
\&{if} $\\{num}\mathbin{\&{div}}4\G\\{denom}$ \1\&{then}\5
$\\{velocity}\K\\{fraction\_four}$\6
\4\&{else} $\\{velocity}\K\\{make\_fraction}(\\{num},\39\\{denom})$;\2\6
\&{end};\par
\fi

\M109. When two \\{scaled} quantities need to be multiplied, we use a scheme
analogous to \\{take\_fraction} but with a different scaling.
Given positive operands, \\{take\_scaled}
computes $p=\lfloor qf/2↑{16}+{1\over2}\rfloor$.

\Y\P\4\&{function}\1\  \37$\\{take\_scaled}(\|q:\\{scaled};\,\35\|f:%
\\{scaled})$: \37\\{scaled};\6
\4\&{var} \37\|p: \37\\{integer};\C{the fraction so far}\6
\\{negative}: \37\\{boolean};\C{should the result be negated?}\6
\|n: \37\\{integer};\C{additional multiple of $q$}\6
\\{be\_careful}: \37\\{integer};\C{disables certain compiler optimizations}\2\6
\&{begin} \37\X106:Reduce to the case that $\|f\G0$ and $\|q>0$\X;\6
\&{if} $\|f<\\{unity}$ \1\&{then}\5
$\|n\K0$\6
\4\&{else} \&{begin} \37$\|n\K\|f\mathbin{\&{div}}\\{unity}$;\5
$\|f\K\|f\mathbin{\&{mod}}\\{unity}$;\6
\&{if} $\|q\L\\{el\_gordo}\mathbin{\&{div}}\|n$ \1\&{then}\5
$\|n\K\|n\ast\|q$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\\{el\_gordo}-\|q$;\6
\&{end};\2\6
\&{end};\2\6
$\|f\K\|f+\\{unity}$;\5
\X110:Compute $p=\lfloor qf/2↑{16}+{1\over2}\rfloor-q$\X;\6
$\\{be\_careful}\K\|n-\\{el\_gordo}$;\6
\&{if} $\\{be\_careful}+\|p>0$ \1\&{then}\6
\&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\\{el\_gordo}-\|p$;\6
\&{end};\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{take\_fraction}\K-(\|n+\|p)$\6
\4\&{else} $\\{take\_fraction}\K\|n+\|p$;\2\6
\&{end};\par
\fi

\M110. \P$\X110:Compute $p=\lfloor qf/2↑{16}+{1\over2}\rfloor-q$\X\S$\6
$\|p\K\O{100000}$;\C{$2↑{15}$; the invariants hold now with $k=16$}\6
\1\&{repeat} \37\&{if} $\\{odd}(\|f)$ \1\&{then}\5
$\|p\K\\{half}(\|p+\|q)$\ \&{else} $\|p\K\\{half}(\|p)$;\2\6
$\|f\K\\{half}(\|f)$;\6
\4\&{until}\5
$\|f=1$\2\par
\U section~109.\fi

\M111. For completeness, there's also \\{make\_scaled}, which computes a
quotient as a \\{scaled} number instead of as a \\{fraction}.

\Y\P\4\&{function}\1\  \37$\\{make\_scaled}(\|p,\39\|q:\\{integer})$: \37%
\\{scaled};\6
\4\&{var} \37\|f: \37\\{integer};\C{the fraction bits, with a leading 1 bit}\6
\|n: \37\\{integer};\C{the integer part of $\vert p/q\vert$}\6
\\{negative}: \37\\{boolean};\C{should the result be negated?}\6
\\{be\_careful}: \37\\{integer};\C{disables certain compiler optimizations}\2\6
\&{begin} \37\&{if} $\|p\G0$ \1\&{then}\5
$\\{negative}\K\\{false}$\6
\4\&{else} \&{begin} \37$\\{negate}(\|p)$;\5
$\\{negative}\K\\{true}$;\6
\&{end};\2\6
\&{if} $\|q\L0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|q)$;\5
$\\{negative}\K\R\\{negative}$;\6
\&{end};\2\6
$\|n\K\|p\mathbin{\&{div}}\|q$;\5
$\|p\K\|p\mathbin{\&{mod}}\|q$;\6
\&{if} $\|n<\O{100000}$ \1\&{then}\5
$\|n\K(\|n-1)\ast\\{unity}$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|n\K\O{17777400000}$;\C{$\O{77776}\ast\\{unity}$}\6
\&{end};\2\6
\X112:Compute $f=\lfloor 2↑{16}(1+p/q)+{1\over2}\rfloor$\X;\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{make\_fraction}\K-(\|f+\|n)$\6
\4\&{else} $\\{make\_fraction}\K\|f+\|n$;\2\6
\&{end};\par
\fi

\M112. The  \&{repeat}  loop here preserves the following invariant relations:
(i)~$0\L\|p<\|q$; (ii)~$fq+p=2↑k(q+p_0)$, where $k$ is an integer and
$p_0$ is the original value of~$p$.

Notice that the computation specifies
$(\|p-\|q)+\|p$ instead of $(\|p+\|p)-\|q$, because the latter could overflow.
Let us hope that optimizing compilers do not miss this point; a
special variable \\{be\_careful} is used to emphasize the necessary
order of computation. Optimizing compilers should keep \\{be\_careful}
in a register, not store it in memory.

\Y\P$\4\X112:Compute $f=\lfloor 2↑{16}(1+p/q)+{1\over2}\rfloor$\X\S$\6
$\|f\K1$;\6
\1\&{repeat} \37$\\{be\_careful}\K\|p-\|q$;\5
$\|p\K\\{be\_careful}+\|p$;\6
\&{if} $\|p\G0$ \1\&{then}\5
$\|f\K\|f+\|f+1$\6
\4\&{else} \&{begin} \37$\|f\K\|f+\|f$;\5
$\|p\K\|p+\|q$;\6
\&{end};\2\6
\4\&{until}\5
$\|f\G\\{unity}$;\2\6
$\\{be\_careful}\K\|p-\|q$;\6
\&{if} $\\{be\_careful}+\|p\G0$ \1\&{then}\5
$\\{incr}(\|f)$\2\par
\U section~111.\fi

\M113. Here is a subroutine that tests rigorously if $ab\G cd$, given integers
$(a,b,c,d)$. In most cases a quick decision is reached.

\Y\P\D \37$\\{return\_geq}(\#)\S$\1\6
\&{begin} \37$\\{ab\_geq\_cd}\K\#$;\5
\&{return};\6
\&{end}\2\par
\Y\P\4\&{function}\1\  \37$\\{ab\_geq\_cd}(\|a,\39\|b,\39\|c,\39\|d:%
\\{integer})$: \37\\{boolean};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|q,\39\|r,\39\|t$: \37\\{integer};\C{temporary registers}\2\6
\&{begin} \37\X114:Reduce to the case that $\|a,\|c\G0$, $\|b,\|d>0$\X;\6
\~ \1\&{loop}\ \&{begin} \37$\|q\K\|a\mathbin{\&{div}}\|d$;\5
$\|r\K\|c\mathbin{\&{div}}\|b$;\6
\&{if} $\|q\I\|r$ \1\&{then}\5
$\\{return\_geq}((\|q>\|r))$;\2\6
$\|t\K\|c\mathbin{\&{mod}}\|b$;\6
\&{if} $\|t=0$ \1\&{then}\5
$\\{return\_geq}(\\{true})$;\2\6
$\|r\K\|a\mathbin{\&{mod}}\|d$;\6
\&{if} $\|r=0$ \1\&{then}\5
$\\{return\_geq}(\\{false})$;\2\6
$\|a\K\|b$;\5
$\|b\K\|r$;\5
$\|c\K\|d$;\5
$\|d\K\|t$;\6
\&{end};\C{now $\|a>\|d>0$ and $\|c>\|b>0$}\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M114. \P$\X114:Reduce to the case that $\|a,\|c\G0$, $\|b,\|d>0$\X\S$\6
\&{if} $\|a<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|a)$;\5
$\\{negate}(\|b)$;\6
\&{end};\2\6
\&{if} $\|c<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|c)$;\5
$\\{negate}(\|d)$;\6
\&{end};\2\6
\&{if} $\|d\L0$ \1\&{then}\6
\&{begin} \37\&{if} $\|b\G0$ \1\&{then}\5
$\\{return\_geq}(\\{true})$;\2\6
\&{if} $\|d=0$ \1\&{then}\5
$\\{return\_geq}((\|a=0))$;\2\6
$\|t\K\|a$;\5
$\|a\K\|c$;\5
$\|c\K\|t$;\5
$\|t\K-\|b$;\5
$\|b\K-\|d$;\5
$\|d\K\|t$;\6
\&{end}\6
\4\&{else} \&{if} $\|b\L0$ \1\&{then}\6
\&{begin} \37\&{if} $\|b<0$ \1\&{then}\6
\&{if} $\|a>0$ \1\&{then}\5
$\\{return\_geq}(\\{false})$;\2\2\6
$\\{return\_geq}((\|c=0))$;\6
\&{end}\2\2\par
\U section~113.\fi

\M115. We conclude this set of elementary routines with some simple rounding
and truncation operations that are coded in a machine-independent fashion.

\Y\P\4\&{function}\1\  \37$\\{round\_scaled}(\|x:\\{scaled})$: \37\\{scaled};%
\C{$2↑{16}\lfloor x/2↑{16}+.5\rfloor$}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{round\_scaled}\K\\{unity}\ast((\|x+\\{half\_unit})\mathbin{\&{div}}%
\\{unity})$\6
\4\&{else} $\\{round\_scaled}\K-\\{unity}\ast((-\|x+\\{half\_unit}-1)\mathbin{%
\&{div}}\\{unity})$;\2\6
\&{end};\7
\4\&{function}\1\  \37$\\{round\_unscaled}(\|x:\\{scaled})$: \37\\{integer};%
\C{$\lfloor x/2↑{16}+.5\rfloor$}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{round\_unscaled}\K(\|x+\\{half\_unit})\mathbin{\&{div}}\\{unity}$\6
\4\&{else} $\\{round\_unscaled}\K-((-\|x+\\{half\_unit}-1)\mathbin{\&{div}}%
\\{unity})$;\2\6
\&{end};\7
\4\&{function}\1\  \37$\\{trunc\_scaled}(\|x:\\{scaled})$: \37\\{scaled};%
\C{$2↑{16}\lfloor x/2↑{16}\rfloor$}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{trunc\_scaled}\K\\{unity}\ast(\|x\mathbin{\&{div}}\\{unity})$\6
\4\&{else} $\\{trunc\_scaled}\K-\\{unity}\ast((-\|x+\\{unity}-1)\mathbin{%
\&{div}}\\{unity})$;\2\6
\&{end};\7
\4\&{function}\1\  \37$\\{trunc\_unscaled}(\|x:\\{scaled})$: \37\\{integer};%
\C{$\lfloor x/2↑{16}\rfloor$}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{trunc\_unscaled}\K\|x\mathbin{\&{div}}\\{unity}$\6
\4\&{else} $\\{trunc\_unscaled}\K-((-\|x+\\{unity}-1)\mathbin{\&{div}}%
\\{unity})$;\2\6
\&{end};\par
\fi

\N116.  \[8] Algebraic and transcendental functions.
\MF\ computes all of the necessary special functions from scratch, without
relying on \\{real} arithmetic or system subroutines for sines, cosines, etc.

\fi

\M117. To get the square root of a \\{scaled} number \|x, we want to calculate
$s=\lfloor 2↑8\sqrt x +{1\over2}\rfloor$. If $x>0$, this is the unique
integer such that $2↑{16}x-s\L s↑2<2↑{16}x+s$. The following subroutine
determines $s$ by an iterative method that maintains the invariant
relations $x=2↑{46-2k}x_0\bmod 2↑{30}$, $0<y=\lfloor 2↑{16-2k}x_0\rfloor
-s↑2+s\L q=2s$, where $x_0$ is the initial value of $x$. The value of~$y$
might, however, be zero at the start of the first iteration.

\Y\P\4\&{function}\1\  \37$\\{square\_rt}(\|x:\\{scaled})$: \37\\{scaled};\6
\4\&{var} \37\|k: \37\\{small\_number};\C{iteration control counter}\6
$\|y,\39\|q$: \37\\{integer};\C{registers for intermediate calculations}\2\6
\&{begin} \37\&{if} $\|x\L0$ \1\&{then}\5
\X118:Handle square root of zero or negative argument\X\6
\4\&{else} \&{begin} \37$\|k\K23$;\5
$\|q\K2$;\6
\&{while} $\|x<\\{fraction\_two}$ \1\&{do}\C{i.e.,  \&{while} $\|x<%
\hbox{$2↑{29}$}$\unskip}\6
\&{begin} \37$\\{decr}(\|k)$;\5
$\|x\K\|x+\|x+\|x+\|x$;\6
\&{end};\2\6
\&{if} $\|x<\\{fraction\_four}$ \1\&{then}\5
$\|y\K0$\6
\4\&{else} \&{begin} \37$\|x\K\|x-\\{fraction\_four}$;\5
$\|y\K1$;\6
\&{end};\2\6
\1\&{repeat} \37\X119:Decrease \|k by 1, maintaining the invariant relations
between \|x, \|y, and~\|q\X;\6
\4\&{until}\5
$\|k=0$;\2\6
$\\{square\_rt}\K\\{half}(\|q)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M118. \P$\X118:Handle square root of zero or negative argument\X\S$\6
\&{begin} \37\&{if} $\|x<0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Square\ root\ of\ "})$;\5
$\\{print\_scaled}(\|x)$;\5
$\\{print}(\.{"\ has\ been\ replaced\ by\ 0"})$;\5
$\\{help2}(\.{"Since\ I\ don\'t\ take\ square\ roots\ of\ negative\
numbers,"})$\6
$(\.{"I\'m\ zeroing\ this\ one.\ Proceed,\ with\ fingers\ crossed."})$;\5
\\{error};\6
\&{end};\2\6
$\\{square\_rt}\K0$;\6
\&{end}\par
\U section~117.\fi

\M119. \P$\X119:Decrease \|k by 1, maintaining the invariant relations between %
\|x, \|y, and~\|q\X\S$\6
$\|x\K\|x+\|x$;\5
$\|y\K\|y+\|y$;\6
\&{if} $\|x\G\\{fraction\_four}$ \1\&{then}\C{note that $\\{fraction\_four}=%
\hbox{$2↑{30}$}$}\6
\&{begin} \37$\|x\K\|x-\\{fraction\_four}$;\5
$\\{incr}(\|y)$;\6
\&{end};\2\6
$\|x\K\|x+\|x$;\5
$\|y\K\|y+\|y-\|q$;\5
$\|q\K\|q+\|q$;\6
\&{if} $\|x\G\\{fraction\_four}$ \1\&{then}\6
\&{begin} \37$\|x\K\|x-\\{fraction\_four}$;\5
$\\{incr}(\|y)$;\6
\&{end};\2\6
\&{if} $\|y>\|q$ \1\&{then}\6
\&{begin} \37$\|y\K\|y-\|q$;\5
$\|q\K\|q+2$;\6
\&{end}\6
\4\&{else} \&{if} $\|y\L0$ \1\&{then}\6
\&{begin} \37$\|q\K\|q-2$;\5
$\|y\K\|y+\|q$;\6
\&{end};\2\2\6
$\\{decr}(\|k)$\par
\U section~117.\fi

\M120. Pythagorean addition $\sqrt{a↑2+b↑2}$ is implemented by an elegant
iterative scheme due to Cleve Moler and Donald Morrison [{\sl IBM Journal
of Research and Development\/ \bf27} (1983), 577--581]. It modifies \|a and~\|b
in such a way that their pythagorean sum remains invariant, while the
smaller argument decreases.

\Y\P\4\&{function}\1\  \37$\\{pyth\_add}(\|a,\39\|b:\\{integer})$: \37%
\\{integer};\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|r: \37\\{fraction};\C{register used to transform \|a and \|b}\6
\\{big}: \37\\{boolean};\C{is the result dangerously near $2↑{31}$?}\2\6
\&{begin} \37$\|a\K\\{abs}(\|a)$;\5
$\|b\K\\{abs}(\|b)$;\6
\&{if} $\|a<\|b$ \1\&{then}\6
\&{begin} \37$\|r\K\|b$;\5
$\|b\K\|a$;\5
$\|a\K\|r$;\6
\&{end};\C{now $0\L\|b\L\|a$}\2\6
\&{if} $\|a>0$ \1\&{then}\6
\&{begin} \37\&{if} $\|a<\\{fraction\_two}$ \1\&{then}\5
$\\{big}\K\\{false}$\6
\4\&{else} \&{begin} \37$\|a\K(\|a+2)\mathbin{\&{div}}4$;\5
$\|b\K(\|b+2)\mathbin{\&{div}}4$;\5
$\\{big}\K\\{true}$;\6
\&{end};\C{we reduced the precision to avoid arithmetic overflow}\2\6
\X121:Replace \|a by an approximation to $\sqrt{a↑2+b↑2}$\X;\6
\&{if} $\\{big}$ \1\&{then}\6
\&{if} $\|a<\\{fraction\_two}$ \1\&{then}\5
$\|a\K\|a+\|a+\|a+\|a$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\|a\K\\{el\_gordo}$;\6
\&{end};\2\2\6
\&{end};\2\6
$\\{pyth\_add}\K\|a$;\6
\&{end};\par
\fi

\M121. The key idea here is to reflect the vector $(a,b)$ about the
line through $(a,b/2)$.

\Y\P$\4\X121:Replace \|a by an approximation to $\sqrt{a↑2+b↑2}$\X\S$\6
\~ \1\&{loop}\ \&{begin} \37$\|r\K\\{make\_fraction}(\|b,\39\|a)$;\5
$\|r\K\\{take\_fraction}(\|r,\39\|r)$;\C{now $r\approx b↑2/a↑2$}\6
\&{if} $\|r=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|r\K\\{make\_fraction}(\|r,\39\\{fraction\_four}+\|r)$;\5
$\|a\K\|a+\\{take\_fraction}(\|a+\|a,\39\|r)$;\5
$\|b\K\\{take\_fraction}(\|b,\39\|r)$;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~120.\fi

\M122. The subroutines for logarithm and exponential involve two tables.
The first is simple: $\\{two\_to\_the}[\|k]$ equals $2↑k$. The second involves
a bit more calculation, which the author claims to have done correctly:
$\\{spec\_log}[\|k]$ is $2↑{27}$ times $\ln\bigl(1/(1-2↑{-k})\bigr)=
2↑{-k}+{1\over2}2↑{-2k}+{1\over3}2↑{-3k}+\cdots\,$, rounded to the
nearest integer.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{two\_to\_the}: \37\&{array} $[0\to30]$ \1\&{of}\5
\\{integer};\C{powers of two}\2\6
\4\\{spec\_log}: \37\&{array} $[1\to28]$ \1\&{of}\5
\\{integer};\C{special logarithms}\2\par
\fi

\M123. \P$\X19:Local variables for initialization\X\mathrel{+}\S$\6
\4\|k: \37\\{small\_number};\C{for short loops}\par
\fi

\M124. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{two\_to\_the}[0]\K1$;\6
\&{for} $\|k\K1\mathrel{\&{to}}30$ \1\&{do}\5
$\\{two\_to\_the}[\|k]\K2\ast\\{two\_to\_the}[\|k-1]$;\2\6
$\\{spec\_log}[1]\K93032640$;\5
$\\{spec\_log}[2]\K38612034$;\5
$\\{spec\_log}[3]\K17922280$;\5
$\\{spec\_log}[4]\K8662214$;\5
$\\{spec\_log}[5]\K4261238$;\5
$\\{spec\_log}[6]\K2113709$;\5
$\\{spec\_log}[7]\K1052693$;\5
$\\{spec\_log}[8]\K525315$;\5
$\\{spec\_log}[9]\K262400$;\5
$\\{spec\_log}[10]\K131136$;\5
$\\{spec\_log}[11]\K65552$;\5
$\\{spec\_log}[12]\K32772$;\5
$\\{spec\_log}[13]\K16385$;\6
\&{for} $\|k\K14\mathrel{\&{to}}27$ \1\&{do}\5
$\\{spec\_log}[\|k]\K\\{two\_to\_the}[27-\|k]$;\2\6
$\\{spec\_log}[28]\K1$;\par
\fi

\M125. Here is the routine that calculates $2↑8$ times the natural logarithm
of a \\{scaled} quantity; it is an integer approximation to $2↑{24}%
\ln(x/2↑{16})$,
when \|x is a given positive integer.

The method is based on exercise 1.2.2--25 in {\sl The Art of Computer
Programming\/}: During the main iteration we have $1\L 2↑{-30}x<1/(1-2↑{1-k})$,
and the logarithm of $2↑{30}x$ remains to be added to an accumulator
register called~$y$. Three auxiliary bits of accuracy are retained in~$y$
during the calculation, and sixteen auxiliary bits to extend \|y are
kept in~\|z during the initial argument reduction. (We add 6553600 to~\|z
and subtract 100 from~\|y so that \|z will not become negative;
also, the actual amount subtracted from~\|y is~96, because we add~4
for rounding before the final division by~8.)

\Y\P\4\&{function}\1\  \37$\\{m\_log}(\|x:\\{scaled})$: \37\\{scaled};\6
\4\&{var} \37$\|y,\39\|z$: \37\\{integer};\C{auxiliary registers}\6
\|k: \37\\{integer};\C{iteration counter}\2\6
\&{begin} \37\&{if} $\|x\L0$ \1\&{then}\5
\X127:Handle non-positive logarithm\X\6
\4\&{else} \&{begin} \37$\|y\K1302456956-96$;\C{$14\times2↑{27}\ln2%
\approx1302456956.421063$}\6
$\|z\K27595+6553600$;\C{and $2↑{16}\times .421063\approx 27595$}\6
\&{while} $\|x<\\{fraction\_four}$ \1\&{do}\6
\&{begin} \37$\|x\K\|x+\|x$;\5
$\|y\K\|y-93032639$;\5
$\|z\K\|z-48782$;\6
\&{end};\C{$2↑{27}\ln2\approx 93032639.74436163$ 			and $2↑{16}\times.74436163%
\approx 48782$}\2\6
$\|y\K\|y+(\|z\mathbin{\&{div}}\\{unity})$;\5
$\|k\K2$;\6
\&{while} $\|x>\\{fraction\_four}+4$ \1\&{do}\5
\X126:Increase \|k until \|x can be multiplied by a factor of $2↑{-k}$, and
adjust $y$ accordingly\X;\2\6
$\\{m\_log}\K\|y\mathbin{\&{div}}8$;\6
\&{end};\2\6
\&{end};\par
\fi

\M126. \P$\X126:Increase \|k until \|x can be multiplied by a factor of
$2↑{-k}$, and adjust $y$ accordingly\X\S$\6
\&{begin} \37$\|z\K((\|x-1)\mathbin{\&{div}}\\{two\_to\_the}[\|k])+1$;\C{$z=%
\lceil x/2↑k\rceil$}\6
\&{while} $\|x<\\{fraction\_four}+\|z$ \1\&{do}\6
\&{begin} \37$\|z\K\\{half}(\|z+1)$;\5
$\|k\K\|k+1$;\6
\&{end};\2\6
$\|y\K\|y+\\{spec\_log}[\|k]$;\5
$\|x\K\|x-\|z$;\6
\&{end}\par
\U section~125.\fi

\M127. \P$\X127:Handle non-positive logarithm\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Logarithm\ of\ "})$;\5
$\\{print\_scaled}(\|x)$;\5
$\\{print}(\.{"\ has\ been\ replaced\ by\ 0"})$;\5
$\\{help2}(\.{"Since\ I\ don\'t\ take\ logs\ of\ non-positive\ numbers,"})$\6
$(\.{"I\'m\ zeroing\ this\ one.\ Proceed,\ with\ fingers\ crossed."})$;\5
\\{error};\5
$\\{m\_log}\K0$;\6
\&{end}\par
\U section~125.\fi

\M128. Conversely, the exponential routine calculates $\exp(x/2↑8)$,
when \|x is \\{scaled}. The result is an integer approximation to
$2↑{16}\exp(x/2↑{24})$, when \|x is regarded as an integer.

\Y\P\4\&{function}\1\  \37$\\{m\_exp}(\|x:\\{scaled})$: \37\\{scaled};\6
\4\&{var} \37\|k: \37\\{small\_number};\C{loop control index}\6
$\|y,\39\|z$: \37\\{integer};\C{auxiliary registers}\2\6
\&{begin} \37\&{if} $\|x>174436200$ \1\&{then}\C{$2↑{24}\ln((2↑{31}-1)/2↑{16})%
\approx 174436199.51$}\6
\&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\\{m\_exp}\K\\{el\_gordo}$;\6
\&{end}\6
\4\&{else} \&{if} $\|x<-197694359$ \1\&{then}\5
$\\{m\_exp}\K0$\C{$2↑{24}\ln(2↑{-1}/2↑{16})\approx-197694359.45$}\6
\4\&{else} \&{begin} \37\&{if} $\|x\L0$ \1\&{then}\6
\&{begin} \37$\|z\K-8\ast\|x$;\5
$\|y\K\O{4000000}$;\C{$y=2↑{20}$}\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\|x\L127919879$ \1\&{then}\5
$\|z\K1023359037-8\ast\|x$\C{$2↑{27}\ln((2↑{31}-1)/2↑{20})\approx
1023359037.125$}\6
\4\&{else} $\|z\K8\ast(174436200-\|x)$;\C{\|z is always nonnegative}\2\6
$\|y\K\\{el\_gordo}$;\6
\&{end};\2\6
\X129:Multiply \|y by $\exp(-z/2↑{27})$\X;\6
\&{if} $\|x\L127919879$ \1\&{then}\5
$\\{m\_exp}\K(\|y+8)\mathbin{\&{div}}16$\ \&{else} $\\{m\_exp}\K\|y$;\2\6
\&{end};\2\2\6
\&{end};\par
\fi

\M129. The idea here is that subtracting $\\{spec\_log}[\|k]$ from \|z
corresponds
to multiplying \|y by $1-2↑{-k}$.

A subtle point (which had to be checked) was that if $x=127919879$, the
value of~\|y will decrease so that $\|y+8$ doesn't overflow. In fact,
$z$ will be 5 in this case, and \|y will decrease by~64 when $\|k=25$
and by~16 when $\|k=27$.

\Y\P$\4\X129:Multiply \|y by $\exp(-z/2↑{27})$\X\S$\6
$\|k\K1$;\6
\&{while} $\|z>0$ \1\&{do}\6
\&{begin} \37\&{while} $\|z\G\\{spec\_log}[\|k]$ \1\&{do}\6
\&{begin} \37$\|z\K\|z-\\{spec\_log}[\|k]$;\5
$\|y\K\|y-1-((\|y-\\{two\_to\_the}[\|k-1])\mathbin{\&{div}}\\{two\_to\_the}[%
\|k])$;\6
\&{end};\2\6
$\\{incr}(\|k)$;\6
\&{end}\2\par
\U section~128.\fi

\M130. The trigonometric subroutines use an auxiliary table such that
$\\{spec\_atan}[\|k]$ contains an approximation to the \\{angle} whose tangent
is~$1/2↑k$.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{spec\_atan}: \37\&{array} $[1\to26]$ \1\&{of}\5
\\{angle};\C{$\arctan2↑{-k}$ times $2↑{20}\cdot180/\pi$}\2\par
\fi

\M131. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{spec\_atan}[1]\K27855475$;\5
$\\{spec\_atan}[2]\K14718068$;\5
$\\{spec\_atan}[3]\K7471121$;\5
$\\{spec\_atan}[4]\K3750058$;\5
$\\{spec\_atan}[5]\K1876857$;\5
$\\{spec\_atan}[6]\K938658$;\5
$\\{spec\_atan}[7]\K469357$;\5
$\\{spec\_atan}[8]\K234682$;\5
$\\{spec\_atan}[9]\K117342$;\5
$\\{spec\_atan}[10]\K58671$;\5
$\\{spec\_atan}[11]\K29335$;\5
$\\{spec\_atan}[12]\K14668$;\5
$\\{spec\_atan}[13]\K7334$;\5
$\\{spec\_atan}[14]\K3667$;\5
$\\{spec\_atan}[15]\K1833$;\5
$\\{spec\_atan}[16]\K917$;\5
$\\{spec\_atan}[17]\K458$;\5
$\\{spec\_atan}[18]\K229$;\5
$\\{spec\_atan}[19]\K115$;\5
$\\{spec\_atan}[20]\K57$;\5
$\\{spec\_atan}[21]\K29$;\5
$\\{spec\_atan}[22]\K14$;\5
$\\{spec\_atan}[23]\K7$;\5
$\\{spec\_atan}[24]\K4$;\5
$\\{spec\_atan}[25]\K2$;\5
$\\{spec\_atan}[26]\K1$;\par
\fi

\M132. Given integers \|x and \|y, not both zero, the \\{n\_atan} function
returns the \\{angle} whose tangent points in the direction $(x,y)$.
This subroutine first determines the correct octant, then solves the
problem for $0\L\|y\L\|x$, then converts the result appropriately to
return an answer in the range $-\\{one\_eighty\_deg}\L\hbox{$\theta$}\L\\{one%
\_eighty\_deg}$.
(The answer is $+\\{one\_eighty\_deg}$ if $\|y=0$ and $\|x<0$, but an answer of
$-\\{one\_eighty\_deg}$ is possible if, for example, $\|y=-1$ and $x=2↑{30}$.)

The octants are represented in a ``Gray code,'' since that turns out
to be computationally simplest.

\Y\P\D \37$\\{negate\_x}=1$\par
\P\D \37$\\{negate\_y}=2$\par
\P\D \37$\\{switch\_x\_and\_y}=4$\par
\P\D \37$\\{first\_octant}=1$\par
\P\D \37$\\{second\_octant}=\\{first\_octant}+\\{switch\_x\_and\_y}$\par
\P\D \37$\\{third\_octant}=\\{first\_octant}+\\{switch\_x\_and\_y}+\\{negate%
\_x}$\par
\P\D \37$\\{fourth\_octant}=\\{first\_octant}+\\{negate\_x}$\par
\P\D \37$\\{fifth\_octant}=\\{first\_octant}+\\{negate\_x}+\\{negate\_y}$\par
\P\D \37$\\{sixth\_octant}=\\{first\_octant}+\\{switch\_x\_and\_y}+\\{negate%
\_x}+\\{negate\_y}$\par
\P\D \37$\\{seventh\_octant}=\\{first\_octant}+\\{switch\_x\_and\_y}+\\{negate%
\_y}$\par
\P\D \37$\\{eighth\_octant}=\\{first\_octant}+\\{negate\_y}$\par
\Y\P\4\&{function}\1\  \37$\\{n\_atan}(\|x,\39\|y:\\{integer})$: \37\\{angle};\6
\4\&{var} \37\|z: \37\\{angle};\C{auxiliary register}\6
\|t: \37\\{integer};\C{temporary storage}\6
\|k: \37\\{small\_number};\C{loop counter}\6
\\{octant}: \37\\{small\_number};\C{octant code}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{octant}\K\\{first\_octant}$\6
\4\&{else} \&{begin} \37$\\{negate}(\|x)$;\5
$\\{octant}\K\\{first\_octant}+\\{negate\_x}$;\6
\&{end};\2\6
\&{if} $\|y<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|y)$;\5
$\\{octant}\K\\{octant}+\\{negate\_y}$;\6
\&{end};\2\6
\&{if} $\|x<\|y$ \1\&{then}\6
\&{begin} \37$\|t\K\|y$;\5
$\|y\K\|x$;\5
$\|x\K\|t$;\5
$\\{octant}\K\\{octant}+\\{switch\_x\_and\_y}$;\6
\&{end};\2\6
\&{if} $\|x=0$ \1\&{then}\5
\X133:Handle undefined arctangent\X\6
\4\&{else} \&{begin} \37\X135:Set \|z to the arctangent determined by $(x,y)$%
\X;\6
\X134:Return an appropriate answer based on \|z and \\{octant}\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M133. \P$\X133:Handle undefined arctangent\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Arctangent\ of\ (0,0)\ is\ taken\ as\
zero"})$;\5
$\\{help2}(\.{"The\ \`angle\'\ between\ two\ identical\ points\ is\
undefined."})$\6
$(\.{"I\'m\ zeroing\ this\ one.\ Proceed,\ with\ fingers\ crossed."})$;\5
\\{error};\5
$\\{n\_atan}\K0$;\6
\&{end}\par
\U section~132.\fi

\M134. \P$\X134:Return an appropriate answer based on \|z and \\{octant}\X\S$\6
\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37$\\{n\_atan}\K\|z$;\6
\4\\{second\_octant}: \37$\\{n\_atan}\K\\{ninety\_deg}-\|z$;\6
\4\\{third\_octant}: \37$\\{n\_atan}\K\\{ninety\_deg}+\|z$;\6
\4\\{fourth\_octant}: \37$\\{n\_atan}\K\\{one\_eighty\_deg}-\|z$;\6
\4\\{fifth\_octant}: \37$\\{n\_atan}\K\|z-\\{one\_eighty\_deg}$;\6
\4\\{sixth\_octant}: \37$\\{n\_atan}\K-\|z-\\{ninety\_deg}$;\6
\4\\{seventh\_octant}: \37$\\{n\_atan}\K\|z-\\{ninety\_deg}$;\6
\4\\{eighth\_octant}: \37$\\{n\_atan}\K-\|z$;\2\6
\&{end}\C{there are no other cases}\par
\U section~132.\fi

\M135. At this point we have $\|x\G\|y\G0$, and $\|x>0$. The numbers are scaled
up
or down until $2↑{28}\L x<2↑{29}$, so that accurate fixed-point calculations
will be made.

\Y\P$\4\X135:Set \|z to the arctangent determined by $(x,y)$\X\S$\6
\&{while} $\|x\G\\{fraction\_two}$ \1\&{do}\6
\&{begin} \37$\|x\K\\{half}(\|x)$;\5
$\|y\K\\{half}(\|y)$;\6
\&{end};\2\6
$\|z\K0$;\6
\&{if} $\|y>0$ \1\&{then}\6
\&{begin} \37\&{while} $\|x<\\{fraction\_one}$ \1\&{do}\6
\&{begin} \37$\|x\K\|x+\|x$;\5
$\|y\K\|y+\|y$;\6
\&{end};\2\6
\X136:Increase \|z to the arctangent determined by $(x,y)$\X;\6
\&{end}\2\par
\U section~132.\fi

\M136. During the calculations of this section, variables \|x and~\|y
represent actual coordinates $(x,2↑{-k}y)$. We will maintain the
condition $\|x\G\|y$, so that the tangent will be at most $2↑{-k}$.
If $x<2y$, the tangent is greater than $2↑{-k-1}$. The transformation
$(a,b)\mapsto(a+b\tan\phi,b-a\tan\phi)$ replaces $(a,b)$ by
coordinates whose angle has decreased by~$\phi$; in the special case
$a=x$, $b=2↑{-k}y$, and $\tan\phi=2↑{-k-1}$, this operation reduces
to the particularly simple iteration shown here. [Cf.~John E. Meggitt,
{\sl IBM Journal of Research and Development\/ \bf6} (1962), 210--226.]

The initial value of \|x will be multiplied by at most
$(1+{1\over2})(1+{1\over8})(1+{1\over32})\cdots\approx 1.7584$; hence
there is no chance of integer overflow.

\Y\P$\4\X136:Increase \|z to the arctangent determined by $(x,y)$\X\S$\6
$\|k\K0$;\6
\1\&{repeat} \37$\|y\K\|y+\|y$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|y>\|x$ \1\&{then}\6
\&{begin} \37$\|z\K\|z+\\{spec\_atan}[\|k]$;\5
$\|t\K\|x$;\5
$\|x\K\|x+(\|y\mathbin{\&{div}}\\{two\_to\_the}[\|k+\|k])$;\5
$\|y\K\|y-\|t$;\6
\&{end};\2\6
\4\&{until}\5
$\|k=15$;\2\6
\1\&{repeat} \37$\|y\K\|y+\|y$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|y>\|x$ \1\&{then}\6
\&{begin} \37$\|z\K\|z+\\{spec\_atan}[\|k]$;\5
$\|y\K\|y-\|x$;\6
\&{end};\2\6
\4\&{until}\5
$\|k=26$\2\par
\U section~135.\fi

\M137. Conversely, the \\{n\_sin\_cos} routine takes an \\{angle} and produces
the sine
and cosine of that angle. The results of this routine are
stored in global integer variables \\{n\_sin} and \\{n\_cos}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{n\_sin},\39\\{n\_cos}$: \37\\{fraction};\C{results computed by \\{n\_sin%
\_cos}}\par
\fi

\M138. Given an integer \|z that is $2↑{20}$ times an angle $\theta$ in
degrees,
the purpose of $\\{n\_sin\_cos}(\|z)$ is to set
$\|x=\hbox{$r\cos\theta$}$ and $\|y=\hbox{$r\sin\theta$}$ (approximately),
for some rather large number~\|r. The maximum of \|x and \|y
will be between $2↑{28}$ and $2↑{30}$, so that there will be hardly
any loss of accuracy. Then \|x and~\|y are divided by~\|r.

\Y\P\4\&{procedure}\1\  \37$\\{n\_sin\_cos}(\|z:\\{angle})$;\C{computes a
multiple of the sine and cosine}\6
\4\&{var} \37\|k: \37\\{small\_number};\C{loop control variable}\6
\|q: \37$0\to7$;\C{specifies the quadrant}\6
\|r: \37\\{fraction};\C{magnitude of $(\|x,\|y)$}\6
$\|x,\39\|y,\39\|t$: \37\\{integer};\C{temporary registers}\2\6
\&{begin} \37\&{while} $\|z<0$ \1\&{do}\5
$\|z\K\|z+\\{three\_sixty\_deg}$;\2\6
$\|z\K\|z\mathbin{\&{mod}}\\{three\_sixty\_deg}$;\C{now $0\L\|z<\\{three\_sixty%
\_deg}$}\6
$\|q\K\|z\mathbin{\&{div}}\\{forty\_five\_deg}$;\5
$\|z\K\|z\mathbin{\&{mod}}\\{forty\_five\_deg}$;\5
$\|x\K\\{fraction\_one}$;\5
$\|y\K\|x$;\6
\&{if} $\R\\{odd}(\|q)$ \1\&{then}\5
$\|z\K\\{forty\_five\_deg}-\|z$;\2\6
\X140:Subtract angle \|z from $(\|x,\|y)$\X;\6
\X139:Convert $(\|x,\|y)$ to the octant determined by~\|q\X;\6
$\|r\K\\{pyth\_add}(\|x,\39\|y)$;\5
$\\{n\_cos}\K\\{make\_fraction}(\|x,\39\|r)$;\5
$\\{n\_sin}\K\\{make\_fraction}(\|y,\39\|r)$;\6
\&{end};\par
\fi

\M139. In this case the octants are numbered sequentially.

\Y\P$\4\X139:Convert $(\|x,\|y)$ to the octant determined by~\|q\X\S$\6
\&{case} $\|q$ \1\&{of}\6
\40: \37\\{do\_nothing};\6
\41: \37\&{begin} \37$\|t\K\|x$;\5
$\|x\K\|y$;\5
$\|y\K\|t$;\6
\&{end};\6
\42: \37\&{begin} \37$\|t\K\|x$;\5
$\|x\K-\|y$;\5
$\|y\K\|t$;\6
\&{end};\6
\43: \37$\\{negate}(\|x)$;\6
\44: \37\&{begin} \37$\\{negate}(\|x)$;\5
$\\{negate}(\|y)$;\6
\&{end};\6
\45: \37\&{begin} \37$\|t\K\|x$;\5
$\|x\K-\|y$;\5
$\|y\K-\|t$;\6
\&{end};\6
\46: \37\&{begin} \37$\|t\K\|x$;\5
$\|x\K\|y$;\5
$\|y\K-\|t$;\6
\&{end};\6
\47: \37$\\{negate}(\|y)$;\2\6
\&{end}\C{there are no other cases}\par
\U section~138.\fi

\M140. The main iteration of \\{n\_sin\_cos} is similar to that of \\{n\_atan}
but
applied in reverse. The values of $\\{spec\_atan}[\|k]$ decrease slowly enough
that this loop is guaranteed to terminate before the (nonexistent) value
$\\{spec\_atan}[27]$ would be required.

\Y\P$\4\X140:Subtract angle \|z from $(\|x,\|y)$\X\S$\6
$\|k\K1$;\6
\&{while} $\|z>0$ \1\&{do}\6
\&{begin} \37\&{if} $\|z\G\\{spec\_atan}[\|k]$ \1\&{then}\6
\&{begin} \37$\|z\K\|z-\\{spec\_atan}[\|k]$;\5
$\|t\K\|x$;\6
$\|x\K\|t+\|y\mathbin{\&{div}}\\{two\_to\_the}[\|k]$;\5
$\|y\K\|y-\|t\mathbin{\&{div}}\\{two\_to\_the}[\|k]$;\6
\&{end};\2\6
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{if} $\|y<0$ \1\&{then}\5
$\|y\K0$\C{this precaution may never be needed}\2\par
\U section~138.\fi

\M141. And now let's complete our collection of numeric utility routines
by considering random number generation.
\MF\ generates pseudo-random numbers with the additive scheme recommended
in Section 3.6 of {\sl The Art of Computer Programming}; however, the
results are random fractions between 0 and $\\{fraction\_one}-1$, inclusive.

There's an auxiliary array \\{randoms} that contains 55 pseudo-random
fractions. Using the recurrence $x_n=(x_{n-55}-x_{n-31})\bmod 2↑{28}$,
we generate batches of 55 new $x_n$'s at a time by calling \\{new\_randoms}.
The global variable \\{j\_random} tells which element has most recently
been consumed.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{randoms}: \37\&{array} $[0\to54]$ \1\&{of}\5
\\{fraction};\C{the last 55 random values generated}\2\6
\4\\{j\_random}: \37$0\to54$;\C{the number of unused \\{randoms}}\par
\fi

\M142. To consume a random fraction, the program below will say `\\{next%
\_random}'
and then it will fetch $\\{randoms}[\\{j\_random}]$.

\Y\P\D \37$\\{next\_random}\S$\1\6
\&{if} $\\{j\_random}=0$ \1\&{then}\5
\\{new\_randoms}\6
\4\&{else} $\\{decr}(\\{j\_random})$\2\2\par
\Y\P\4\&{procedure}\1\  \37\\{new\_randoms};\6
\4\&{var} \37\|k: \37$0\to54$;\C{index into \\{randoms}}\6
\|x: \37\\{fraction};\C{accumulator}\2\6
\&{begin} \37\&{for} $\|k\K0\mathrel{\&{to}}23$ \1\&{do}\6
\&{begin} \37$\|x\K\\{randoms}[\|k]-\\{randoms}[\|k+31]$;\6
\&{if} $\|x<0$ \1\&{then}\5
$\|x\K\|x+\\{fraction\_one}$;\2\6
$\\{randoms}[\|k]\K\|x$;\6
\&{end};\2\6
\&{for} $\|k\K24\mathrel{\&{to}}54$ \1\&{do}\6
\&{begin} \37$\|x\K\\{randoms}[\|k]-\\{randoms}[\|k-24]$;\6
\&{if} $\|x<0$ \1\&{then}\5
$\|x\K\|x+\\{fraction\_one}$;\2\6
$\\{randoms}[\|k]\K\|x$;\6
\&{end};\2\6
$\\{j\_random}\K54$;\6
\&{end};\par
\fi

\M143. To initialize the \\{randoms} table, we call the following routine.

\Y\P\4\&{procedure}\1\  \37$\\{init\_randoms}(\\{seed}:\\{scaled})$;\6
\4\&{var} \37$\|j,\39\\{jj},\39\|k$: \37\\{fraction};\C{more or less random
integers}\6
\|i: \37$0\to54$;\C{index into \\{randoms}}\2\6
\&{begin} \37$\|j\K\\{abs}(\\{seed})$;\6
\&{while} $\|j\G\\{fraction\_one}$ \1\&{do}\5
$\|j\K\\{half}(\|j)$;\2\6
$\|k\K1$;\6
\&{for} $\|i\K0\mathrel{\&{to}}54$ \1\&{do}\6
\&{begin} \37$\\{jj}\K\|k$;\5
$\|k\K\|j-\|k$;\5
$\|j\K\\{jj}$;\6
\&{if} $\|k<0$ \1\&{then}\5
$\|k\K\|k+\\{fraction\_one}$;\2\6
$\\{randoms}[(\|i+21)\mathbin{\&{mod}}55]\K\|j$;\6
\&{end};\2\6
\\{new\_randoms};\5
\\{new\_randoms};\5
\\{new\_randoms};\C{``warm up'' the array}\6
\&{end};\par
\fi

\M144. To produce a uniform random number in the range $0\L\|u<\|x$, given a
positive
\\{scaled} value~\|x, we proceed as shown here.

Note that the call of \\{take\_fraction} will produce the values 0 and~\|x
with about half the probability that it will produce any other particular
values between 0 and~\|x, because it rounds its answers.

\Y\P\4\&{function}\1\  \37$\\{unif\_rand}(\|x:\\{scaled})$: \37\\{scaled};\6
\4\&{var} \37\|y: \37\\{scaled};\C{trial value}\2\6
\&{begin} \37\&{if} $\|x\L0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Uniform\ random\ number\ less\ than\ "})$;\5
$\\{print\_scaled}(\|x)$;\5
$\\{print}(\.{"\ has\ been\ replaced\ by\ 0"})$;\5
$\\{help2}(\.{"The\ upper\ bound\ on\ a\ random\ number\ should\ be\ positive,\
so"})$\6
$(\.{"I\'m\ zeroing\ this\ one.\ Proceed,\ with\ fingers\ crossed."})$;\5
\\{error};\5
$\\{unif\_rand}\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37\\{next\_random};\5
$\|y\K\\{take\_fraction}(\|x,\39\\{randoms}[\\{j\_random}])$;\6
\&{if} $\|y=\|x$ \1\&{then}\5
$\\{unif\_rand}\K0$\6
\4\&{else} $\\{unif\_rand}\K\|y$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M145. Finally, a normal deviate with mean zero and unit standard deviation
can readily be obtained with the ratio method (Algorithm 3.4.1R in
{\sl The Art of Computer Programming\/}).

\Y\P\4\&{function}\1\  \37\\{norm\_rand}: \37\\{scaled};\6
\4\&{var} \37$\|x,\39\|u,\39\|l$: \37\\{integer};\C{what the book would call
$2↑{16}X$, $2↑{28}U$, 	and $-2↑{24}\ln U$}\2\6
\&{begin} \37\1\&{repeat} \37\1\&{repeat} \37\\{next\_random};\5
$\|x\K\\{take\_fraction}(112429,\39\\{randoms}[\\{j\_random}]-\\{fraction%
\_half})$;\C{$2↑{16}\sqrt{8/e}\approx 112428.82793$}\6
\\{next\_random};\5
$\|u\K\\{randoms}[\\{j\_random}]$;\6
\4\&{until}\5
$\\{abs}(\|x)<\|u$;\2\6
$\|x\K\\{make\_fraction}(\|x,\39\|u)$;\5
$\|l\K139548960-\\{m\_log}(\|u)$;\C{$2↑{24}\cdot12\ln2\approx139548959.6165$}\6
\4\&{until}\5
$\\{ab\_geq\_cd}(1024,\39\|l,\39\|x,\39\|x)$;\2\6
$\\{norm\_rand}\K\|x$;\6
\&{end};\par
\fi

\N146.  \[9] Packed data.
In order to make efficient use of storage space, \MF\ bases its major data
structures on a \\{memory\_word}, which contains either a (signed) integer,
possibly scaled, or a small number of fields that are one half or one
quarter of the size used for storing integers.

If \|x is a variable of type \\{memory\_word}, it contains up to four
fields that can be referred to as follows:
$$\vbox{\halign{\hfil#&#\hfil&#\hfil\cr
\|x&.\\{int}&(an \\{integer})\cr
\|x&.\\{sc}\qquad&(a \\{scaled} integer)\cr
\|x.\\{hh}.\\{lh}, \|x.\\{hh}&.\\{rh}&(two halfword fields)\cr
\|x.\\{hh}.\\{b0}, \|x.\\{hh}.\\{b1}, \|x.\\{hh}&.\\{rh}&(two quarterword
fields, one halfword
field)\cr
\|x.\\{qqqq}.\\{b0}, \|x.\\{qqqq}.\\{b1}, \|x.\\{qqqq}&.\\{b2}, \|x.\\{qqqq}.%
\\{b3}\hskip-100pt
&\qquad\qquad\qquad(four quarterword fields)\cr}}$$
This is somewhat cumbersome to write, and not very readable either, but
macros will be used to make the notation shorter and more transparent.
The \PASCAL\ code below gives a formal definition of \\{memory\_word} and
its subsidiary types, using packed variant records. \MF\ makes no
assumptions about the relative positions of the fields within a word.

Since we are assuming 32-bit integers, a halfword must contain at least
16 bits, and a quarterword must contain at least 8 bits.
But it doesn't hurt to have more bits; for example, with enough 36-bit
words you might be able to have \\{mem\_max} as large as 262142.

N.B.: Valuable memory space will be dreadfully wasted unless \MF\ is compiled
by a \PASCAL\ that packs all of the \\{memory\_word} variants into
the space of a single integer. Some \PASCAL\ compilers will pack an
integer whose subrange is `$0\to255$' into an eight-bit field, but others
insist on allocating space for an additional sign bit; on such systems you
can get 256 values into a quarterword only if the subrange is `$-128\to127$'.

The present implementation tries to accommodate as many variations as possible,
so it makes rather general assumptions. If integers having the subrange
`$\\{min\_quarterword}\to\\{max\_quarterword}$' can be packed into a
quarterword,
and if integers having the subrange `$\\{min\_halfword}\to\\{max\_halfword}$'
can be packed into a halfword, everything should work satisfactorily.

It is usually most efficient to have $\\{min\_quarterword}=\\{min%
\_halfword}=0$,
so one should try to achieve this unless it causes a severe problem.
The values defined here are recommended for most 32-bit computers.

\Y\P\D \37$\\{min\_quarterword}=0$\C{smallest allowable value in a %
\\{quarterword}}\par
\P\D \37$\\{max\_quarterword}=255$\C{largest allowable value in a %
\\{quarterword}}\par
\P\D \37$\\{min\_halfword}\S0$\C{smallest allowable value in a \\{halfword}}\par
\P\D \37$\\{max\_halfword}\S65535$\C{largest allowable value in a \\{halfword}}%
\par
\fi

\M147. Here are the inequalities that the quarterword and halfword values
must satisfy (or rather, the inequalities that they mustn't satisfy):

\Y\P$\4\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $(\\{min\_quarterword}>0)\V(\\{max\_quarterword}<127)$ \1\&{then}\5
$\\{bad}\K11$;\2\6
\&{if} $(\\{min\_halfword}>0)\V(\\{max\_halfword}<32767)$ \1\&{then}\5
$\\{bad}\K12$;\2\6
\&{if} $(\\{min\_quarterword}<\\{min\_halfword})\V\30(\\{max\_quarterword}>%
\\{max\_halfword})$ \1\&{then}\5
$\\{bad}\K13$;\2\6
\&{if} $(\\{mem\_base}<\\{min\_halfword})\V(\\{mem\_max}\G\\{max\_halfword})$ %
\1\&{then}\5
$\\{bad}\K14$;\2\6
\&{if} $(\\{save\_size}>\\{max\_halfword})\V(\\{max\_strings}>\\{max%
\_halfword})$ \1\&{then}\5
$\\{bad}\K15$;\2\6
\&{if} $\\{buf\_size}>\\{max\_halfword}$ \1\&{then}\5
$\\{bad}\K16$;\2\par
\fi

\M148. The operation of adding or subtracting \\{min\_halfword} occurs quite
frequently in \MF, so it is convenient to abbreviate this operation
by using the macros \\{hi} and \\{ho} for input and output to and from
halfword format. \MF\ will run faster with respect to compilers
that don't optimize expressions like `$\|x+0$' and `$\|x-0$', if these
macros are simplified in the obvious way when $\\{min\_halfword}=0$.

\Y\P\D \37$\\{hi}(\#)\S\#+\\{min\_halfword}$\C{to put a sixteen-bit item into a
halfword}\par
\P\D \37$\\{ho}(\#)\S\#-\\{min\_halfword}$\C{to take a sixteen-bit item from a
halfword}\par
\fi

\M149. The reader should study the following definitions closely:

\Y\P\D \37$\\{sc}\S\\{int}$\C{\\{scaled} data is equivalent to \\{integer}}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{quarterword}=\\{min\_quarterword}\to\\{max\_quarterword}$;\C{1/4 of a word}%
\6
$\\{halfword}=\\{min\_halfword}\to\\{max\_halfword}$;\C{1/2 of a word}\6
$\\{two\_choices}=1\to2$;\C{used when there are two variants in a record}\6
$\\{three\_choices}=1\to3$;\C{used when there are three variants in a record}\6
$\\{two\_halves}=$\1\5
\&{packed} \37\1\&{record} \37\\{rh}: \37\\{halfword};\2\6
\&{case} $\\{two\_choices}$ \1\&{of}\6
\41: \37$(\\{lh}:\\{halfword})$;\6
\42: \37$(\\{b0}:\\{quarterword};\,\35\\{b1}:\\{quarterword})$;\2\6
\&{end};\2\6
$\\{four\_quarters}=$\1\5
\&{packed} \37\1\&{record} \37\\{b0}: \37\\{quarterword};\6
\4\\{b1}: \37\\{quarterword};\6
\4\\{b2}: \37\\{quarterword};\6
\4\\{b3}: \37\\{quarterword};\2\6
\&{end};\2\6
$\\{memory\_word}=$\1\5
\1\&{record} \37\2\6
\&{case} $\\{three\_choices}$ \1\&{of}\6
\41: \37$(\\{int}:\\{integer})$;\6
\42: \37$(\\{hh}:\\{two\_halves})$;\6
\43: \37$(\\{qqqq}:\\{four\_quarters})$;\2\6
\&{end};\2\6
$\\{word\_file}=$\1\5
\&{file} \1\&{of}\5
\\{memory\_word};\2\2\par
\fi

\M150. When debugging, we may want to print a \\{memory\_word} without knowing
what type it is; so we print it in all modes.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\_word}(\|w:\\{memory\_word})$;%
\C{prints \|w in all ways}\2\6
\&{begin} \37$\\{print\_int}(\|w.\\{int})$;\5
$\\{print\_char}(\.{"\ "})$;\6
$\\{print\_scaled}(\|w.\\{sc})$;\5
$\\{print\_char}(\.{"\ "})$;\5
\\{print\_ln};\6
$\\{print\_int}(\|w.\\{hh}.\\{lh})$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{b0})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{b1})$;\5
$\\{print\_char}(\.{";"})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{rh})$;\5
$\\{print\_char}(\.{"\ "})$;\6
$\\{print\_int}(\|w.\\{qqqq}.\\{b0})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b1})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b2})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b3})$;\6
\&{end};\6
\&{gubed}\par
\fi

\N151.  \[10] Dynamic memory allocation.
The \MF\ system does nearly all of its own memory allocation, so that it
can readily be transported into environments that do not have automatic
facilities for strings, garbage collection, etc., and so that it can be in
control of what error messages the user receives. The dynamic storage
requirements of \MF\ are handled by providing a large array \\{mem} in
which consecutive blocks of words are used as nodes by the \MF\ routines.

Pointer variables are indices into this array, or into another array
called \\{eqtb} that will be explained below. A pointer variable might
also be a special flag that lies outside the bounds of \\{mem}, so we
allow pointers to assume any \\{halfword} value. The minimum halfword
value represents a null pointer.

\Y\P\D \37$\\{pointer}\S\\{halfword}$\C{a flag or a location in \\{mem} or %
\\{eqtb}}\par
\P\D \37$\\{null}\S\\{mem\_base}$\C{the null pointer}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{temp\_ptr}: \37\\{pointer};\C{a pointer variable for occasional emergency
use}\par
\fi

\M152. The \\{mem} array is divided once and for all into two regions that are
allocated separately. Locations less than \\{hi\_mem\_base} are used for
storing
variable-length records consisting of two or more words each. This region
is maintained using an algorithm similar to the one described in exercise
2.5--19 of {\sl The Art of Computer Programming}. However, no size field
appears in the allocated nodes: the program is responsible for knowing the
relevant size when a node is freed. The remaining region of \\{mem} is
allocated in single words using a conventional \.{AVAIL} stack.

Incidentally, it would be feasible to construct implementations of \MF\ that
are based on 16-bit words instead of 32-bit words, for machines having
comparatively small memories. In such cases it would be desirable to have
two parallel arrays for the upper part of memory, called say \\{mem\_link}$[%
\|p]$
and \\{mem\_info}$[\|p]$,
since the single-word region in the present implementation
consists entirely of \\{memory\_word} items of type \\{two\_halves}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{mem}: \37\&{array} $[\\{mem\_base}\to\\{mem\_max}]$ \1\&{of}\5
\\{memory\_word};\C{the big dynamic storage area}\2\par
\fi

\M153. In order to study the memory requirements of particular applications, it
is possible to prepare a version of \MF\ that keeps track of current and
maximum memory usage. When code between the delimiters  \&{stat}  $\ldots$
  \&{tats}  is not ``commented out,'' \MF\ will run a bit slower but it will
report these statistics when \\{tracing\_stats} is positive.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{var\_used},\39\\{dyn\_used}$: \37\\{integer};\C{how much memory is in
use}\6
\4\\{max\_var\_used}: \37\\{integer};\C{how much memory was in use}\par
\fi

\M154. Let's consider the one-word memory region first, since it's the
simplest. The pointer variable \\{mem\_end} holds the highest-numbered location
of \\{mem} that has ever been used. The free locations of \\{mem} that
occur between \\{hi\_mem\_base} and \\{mem\_end}, inclusive, are of type
\\{two\_halves}, and we write $\\{info}(\|p)$ and $\\{link}(\|p)$ for the %
\\{lh}
and \\{rh} fields of $\\{mem}[\|p]$ when it is of this type. The single-word
free locations form a linked list
$$\\{avail},\;\hbox{$\\{link}(\\{avail})$},\;\hbox{$\\{link}(\\{link}(%
\\{avail}))$},\;\ldots$$
terminated by \\{null}.

\Y\P\D \37$\\{link}(\#)\S\\{mem}[\#].\\{hh}.\\{rh}$\C{the \\{link} field of a
memory word}\par
\P\D \37$\\{info}(\#)\S\\{mem}[\#].\\{hh}.\\{lh}$\C{the \\{info} field of a
memory word}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{avail}: \37\\{pointer};\C{head of the list of available one-word nodes}\6
\4\\{mem\_end}: \37\\{pointer};\C{the last one-word node used in \\{mem}}\par
\fi

\M155. If one-word memory is exhausted, it might mean that the user has
forgotten
a right brace. We will define some procedures later that try to help
pinpoint the trouble.

\Y\P\X205:Declare the procedure called \\{show\_token\_list}\X\6
\X531:Declare the procedure called \\{runaway}\X\par
\fi

\M156. The function \\{get\_avail} returns a pointer to a new one-word node
whose
\\{link} field is null. However, \MF\ will halt if there is no more room left.

\Y\P\4\&{function}\1\  \37\\{get\_avail}: \37\\{pointer};\C{single-word node
allocation}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node being got}\2\6
\&{begin} \37$\|p\K\\{avail}$;\C{get top location in the \\{avail} stack}\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{avail}\K\\{link}(\\{avail})$\C{and pop it off}\6
\4\&{else} \&{if} $\\{mem\_end}<\\{mem\_max}$ \1\&{then}\C{or go into virgin
territory}\6
\&{begin} \37$\\{incr}(\\{mem\_end})$;\5
$\|p\K\\{mem\_end}$;\6
\&{end}\6
\4\&{else} \&{begin} \37\\{runaway};\C{if memory is exhausted, display possible
runaway text}\6
$\\{overflow}(\.{"macro/pixel\ memory\ size"},\39\\{mem\_max}+1-\\{hi\_mem%
\_base})$;\C{quit; all one-word nodes are busy}\6
\&{end};\2\2\6
$\\{link}(\|p)\K\\{null}$;\C{provide an oft-desired initialization of the new
node}\6
\&{stat} \37$\\{incr}(\\{dyn\_used})$;\ \&{tats}\C{maintain statistics}\6
$\\{get\_avail}\K\|p$;\6
\&{end};\par
\fi

\M157. Conversely, a one-word node is recycled by calling \\{free\_avail}.

\Y\P\D \37$\\{free\_avail}(\#)\S$\C{single-word node liberation}\6
\&{begin} \37$\\{link}(\#)\K\\{avail}$;\5
$\\{avail}\K\#$;\6
\&{stat} \37$\\{decr}(\\{dyn\_used})$;\ \&{tats}\6
\&{end}\par
\fi

\M158. There's also a \\{fast\_get\_avail} routine, which saves the
procedure-call
overhead at the expense of extra programming. This macro is used in
the places that would otherwise account for the most calls of \\{get\_avail}.

\Y\P\D \37$\\{fast\_get\_avail}(\#)\S\hbox{}$\6
\&{begin} \37$\#\K\\{avail}$;\C{avoid \\{get\_avail} if possible, to save time}%
\6
\&{if} $\#=\\{null}$ \1\&{then}\5
$\#\K\\{get\_avail}$\6
\4\&{else} \&{begin} \37$\\{avail}\K\\{link}(\#)$;\5
$\\{link}(\#)\K\\{null}$;\6
\&{stat} \37$\\{incr}(\\{dyn\_used})$;\ \&{tats}\6
\&{end};\2\6
\&{end}\par
\fi

\M159. The available-space list that keeps track of the variable-size portion
of \\{mem} is a nonempty, doubly-linked circular list of empty nodes,
pointed to by the roving pointer \\{rover}.

Each empty node has size 2 or more; the first word contains the special
value \\{max\_halfword} in its \\{link} field and the size in its \\{info}
field;
the second word contains the two pointers for double linking.

Each nonempty node also has size 2 or more. Its first word is of type
\\{two\_halves}\kern-1pt, and its \\{link} field is never equal to \\{max%
\_halfword}.
Otherwise there is complete flexibility with respect to the contents
of its other fields and its other words.

\Y\P\D \37$\\{empty\_flag}\S\\{max\_halfword}$\C{the \\{link} of an empty
variable-size node}\par
\P\D \37$\\{is\_empty}(\#)\S(\\{link}(\#)=\\{empty\_flag})$\C{tests for empty
node}\par
\P\D \37$\\{node\_size}\S\\{info}$\C{the size field in empty variable-size
nodes}\par
\P\D \37$\\{llink}(\#)\S\\{info}(\#+1)$\C{left link in doubly-linked list of
empty nodes}\par
\P\D \37$\\{rlink}(\#)\S\\{link}(\#+1)$\C{right link in doubly-linked list of
empty nodes}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{rover}: \37\\{pointer};\C{points to some node in the list of empties}\par
\fi

\M160. A call to \\{get\_node} with argument \|s returns a pointer to a new
node
of size~\|s, which must be 2~or more. The \\{link} field of the first word
of this new node is set to null. An overflow stop occurs if no suitable
space exists.

If \\{get\_node} is called with $s=2↑{30}$, it simply merges adjacent free
areas and returns the value \\{max\_halfword}.

\Y\P\4\&{function}\1\  \37$\\{get\_node}(\|s:\\{integer})$: \37\\{pointer};%
\C{variable-size node liberation}\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the node currently under inspection}\6
\|q: \37\\{pointer};\C{the node physically after node \|p}\6
\|r: \37\\{integer};\C{the newly allocated node, or a candidate for this honor}%
\2\6
\&{begin} \37$\|p\K\\{rover}$;\C{start at some free node in the ring}\6
\1\&{repeat} \37\X162:Try to allocate within node \|p and its physical
successors, and \&{goto} \\{found} if allocation was possible\X;\6
$\|p\K\\{rlink}(\|p)$;\C{move to the next node in the ring}\6
\4\&{until}\5
$\|p=\\{rover}$;\C{repeat until the whole list has been traversed}\2\6
\&{if} $\|s=\O{10000000000}$ \1\&{then}\6
\&{begin} \37$\\{get\_node}\K\\{max\_halfword}$;\5
\&{return};\6
\&{end};\2\6
$\\{overflow}(\.{"point/path\ memory\ size"},\39\\{hi\_mem\_base}-\\{mem%
\_base})$;\C{sorry, nothing satisfactory is left}\6
\4\\{found}: \37$\\{link}(\|r)\K\\{null}$;\C{this node is now nonempty}\6
\&{stat} \37$\\{var\_used}\K\\{var\_used}+\|s$;\C{maintain usage statistics}\6
\&{if} $\\{var\_used}>\\{max\_var\_used}$ \1\&{then}\5
$\\{max\_var\_used}\K\\{var\_used}$;\2\6
\&{tats}\6
$\\{get\_node}\K\|r$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M161. The following operations remove an empty node from the doubly-linked
list, knowing that it is not the only item in the list.

\Y\P\D \37$\\{remove\_node}(\#)\S$\6
\&{if} $\#=\\{rover}$ \1\&{then}\5
$\\{rover}\K\\{rlink}(\#)$;\2\6
$\\{llink}(\\{rlink}(\#))\K\\{llink}(\#)$;\5
$\\{rlink}(\\{llink}(\#))\K\\{rlink}(\#)$\par
\fi

\M162. \P$\X162:Try to allocate within node \|p and its physical successors,
and \&{goto} \\{found} if allocation was possible\X\S$\6
$\|q\K\|p+\\{node\_size}(\|p)$;\C{find the physical successor}\6
\&{while} $\\{is\_empty}(\|q)$ \1\&{do}\C{merge \|p with \|q}\6
\&{begin} \37$\\{remove\_node}(\|q)$;\5
$\|q\K\|q+\\{node\_size}(\|q)$;\6
\&{end};\2\6
$\|r\K\|q-\|s$;\6
\&{if} $\|r>\|p+1$ \1\&{then}\5
\X163:Allocate from the top of node \|p and \&{goto} \\{found}\X;\2\6
\&{if} $(\|r=\|p)\W((\\{rlink}(\|p)\I\\{rover})\V(\\{llink}(\|p)\I\\{rover}))$ %
\1\&{then}\5
\X164:Allocate entire node \|p and \&{goto} \\{found}\X;\2\6
$\\{node\_size}(\|p)\K\|q-\|p$\C{reset the size in case it grew}\par
\U section~160.\fi

\M163. \P$\X163:Allocate from the top of node \|p and \&{goto} \\{found}\X\S$\6
\&{begin} \37$\\{node\_size}(\|p)\K\|r-\|p$;\C{store the remaining size}\6
$\\{rover}\K\|p$;\C{start searching here next time}\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~162.\fi

\M164. \P$\X164:Allocate entire node \|p and \&{goto} \\{found}\X\S$\6
\&{begin} \37$\\{remove\_node}(\|p)$;\C{delete node \|p from the ring}\6
$\\{rover}\K\\{rlink}(\|p)$;\C{let \\{rover} rove around}\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~162.\fi

\M165. Conversely, when some variable-size node \|p of size \|s is no longer
needed,
the operation $\\{free\_node}(\|p,\|s)$ will make its words available, by
inserting
\|p as a new empty node just before where \\{rover} now points.

\Y\P\4\&{procedure}\1\  \37$\\{free\_node}(\|p:\\{pointer};\,\35\|s:%
\\{halfword})$;\C{variable-size node 	liberation}\6
\4\&{var} \37\|q: \37\\{pointer};\C{$\\{llink}(\\{rover})$}\2\6
\&{begin} \37\&{if} $\X168:Node \|p isn't in the variable-size \\{mem}\X$ \1%
\&{then}\5
$\\{confusion}(\.{"freenode"})$;\2\6
$\\{node\_size}(\|p)\K\|s$;\5
$\\{link}(\|p)\K\\{empty\_flag}$;\5
$\|q\K\\{llink}(\\{rover})$;\5
$\\{llink}(\|p)\K\|q$;\5
$\\{rlink}(\|p)\K\\{rover}$;\C{set both links}\6
$\\{llink}(\\{rover})\K\|p$;\5
$\\{rlink}(\|q)\K\|p$;\C{insert \|p into the ring}\6
\&{stat} \37$\\{var\_used}\K\\{var\_used}-\|s$;\ \&{tats}\C{maintain
statistics}\6
\&{end};\par
\fi

\M166. Just before \.{INIMF} writes out the memory, it sorts the doubly linked
available space list. The list is probably very short at such times, so a
simple insertion sort is used. The smallest available location will be
pointed to by \\{rover}, the next-smallest by $\\{rlink}(\\{rover})$, etc.

\Y\P\&{init} \37\&{procedure}\1\  \37\\{sort\_avail};\C{sorts the available
variable-size nodes 	by location}\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{indices into \\{mem}}\6
\\{old\_rover}: \37\\{pointer};\C{initial \\{rover} setting}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\O{10000000000})$;\C{merge adjacent free
areas}\6
$\|p\K\\{rlink}(\\{rover})$;\5
$\\{rlink}(\\{rover})\K\\{max\_halfword}$;\5
$\\{old\_rover}\K\\{rover}$;\6
\&{while} $\|p\I\\{old\_rover}$ \1\&{do}\5
\X167:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X;\2\6
$\|p\K\\{rover}$;\6
\&{while} $\\{rlink}(\|p)\I\\{max\_halfword}$ \1\&{do}\6
\&{begin} \37$\\{llink}(\\{rlink}(\|p))\K\|p$;\5
$\|p\K\\{rlink}(\|p)$;\6
\&{end};\2\6
$\\{rlink}(\|p)\K\\{rover}$;\5
$\\{llink}(\\{rover})\K\|p$;\6
\&{end};\6
\&{tini}\par
\fi

\M167. The following  \&{while}  loop terminates, since the list that starts at
\\{rover} ends with \\{max\_halfword} during the sorting procedure.

\Y\P$\4\X167:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X\S$\6
\&{if} $\|p<\\{rover}$ \1\&{then}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{rlink}(\|q)$;\5
$\\{rlink}(\|q)\K\\{rover}$;\5
$\\{rover}\K\|q$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|q\K\\{rover}$;\6
\&{while} $\\{rlink}(\|q)<\|p$ \1\&{do}\5
$\|q\K\\{rlink}(\|q)$;\2\6
$\|r\K\\{rlink}(\|p)$;\5
$\\{rlink}(\|p)\K\\{rlink}(\|q)$;\5
$\\{rlink}(\|q)\K\|p$;\5
$\|p\K\|r$;\6
\&{end}\2\par
\U section~166.\fi

\N168.  \[11] Memory layout.
Some areas of \\{mem} are dedicated to fixed usage, since static allocation is
more efficient than dynamic allocation when we can get away with it. For
example, locations \\{mem\_base} to $\\{mem\_base}+2$ are always used to store
the
specification for null pen coordinates that are `$(0,0)$'. The
following macro definitions accomplish the static allocation by giving
symbolic names to the fixed positions. Dynamic allocation of variable-size
nodes is restricted to locations \\{first\_mem} through $(\\{hi\_mem%
\_base}-1)$,
and single-word nodes are dynamically allocated in locations \\{second\_mem}
through \\{mem\_max}, inclusive.

\Y\P\D \37$\\{null\_coords}\S\\{mem\_base}$\C{specification for pen offsets of
$(0,0)$}\par
\P\D \37$\\{null\_pen}\S\\{null\_coords}+3$\C{we will define $\\{coord\_node%
\_size}=3$}\par
\P\D \37$\\{dep\_head}\S\\{null\_pen}+10$\C{and $\\{pen\_node\_size}=10$}\par
\P\D \37$\\{left\_delta}\S\\{dep\_head}+1$\C{we use locations $\\{left%
\_delta}+1\to\\{left\_delta}+2$ only}\par
\P\D \37$\\{right\_delta}\S\\{left\_delta}+2$\C{and $\\{right\_delta}+1\to%
\\{right\_delta}+2$ only}\par
\P\D \37$\\{end\_attr}\S\\{right\_delta}+1$\C{and $\\{end\_attr}+2$ only}\par
\P\D \37$\\{first\_mem}\S\\{end\_attr}+3$\C{first dynamically allocatable word
	in the variable-size \\{mem}}\Y\par
\P\D \37$\\{sentinel}\S\\{hi\_mem\_base}$\C{end of sorted lists}\par
\P\D \37$\\{temp\_head}\S\\{hi\_mem\_base}+1$\C{head of a temporary list of
some kind}\par
\P\D \37$\\{identity\_macro}\S\\{hi\_mem\_base}+2$\C{special macro for
expression backup}\par
\P\D \37$\\{repeat\_the\_loop}\S\\{hi\_mem\_base}+3$\C{special token for loop
repetition}\par
\P\D \37$\\{second\_mem}\S\\{hi\_mem\_base}+4$\C{first dynamically allocatable
word in 	the one-word \\{mem}}\par
\Y\P$\4\X168:Node \|p isn't in the variable-size \\{mem}\X\S$\6
$(\|p<\\{first\_mem})\V(\|p\G\\{hi\_mem\_base})$\par
\U section~165.\fi

\M169. The following code gets \\{mem} off to a good start, when \MF\ is
initializing itself the slow way.

\Y\P$\4\X19:Local variables for initialization\X\mathrel{+}\S$\6
\4\|k: \37\\{integer};\C{index into \\{mem}, \\{eqtb}, etc.}\par
\fi

\M170. \P$\X170:Initialize table entries (done by \.{INIMF} only)\X\S$\6
$\\{rover}\K\\{first\_mem}$;\5
$\\{link}(\\{rover})\K\\{empty\_flag}$;\C{now initialize the dynamic memory}\6
$\\{node\_size}(\\{rover})\K\\{hi\_mem\_base}-\\{rover}$;\C{which is one big
available node}\6
$\\{llink}(\\{rover})\K\\{rover}$;\5
$\\{rlink}(\\{rover})\K\\{rover}$;\6
$\\{link}(\\{hi\_mem\_base})\K\\{null}$;\5
$\\{info}(\\{hi\_mem\_base})\K\\{null}$;\6
\&{for} $\|k\K\\{hi\_mem\_base}+1\mathrel{\&{to}}\\{second\_mem}-1$ \1\&{do}\5
$\\{mem}[\|k]\K\\{mem}[\\{hi\_mem\_base}]$;\C{clear list heads}\2\6
$\\{avail}\K\\{null}$;\5
$\\{mem\_end}\K\\{second\_mem}-1$;\C{initialize the one-word memory}\6
$\\{var\_used}\K\\{first\_mem}-\\{mem\_base}$;\5
$\\{dyn\_used}\K\\{second\_mem}-\\{hi\_mem\_base}$;\5
$\\{max\_var\_used}\K\\{var\_used}$;\C{initialize statistics}\par
\A sections~193, 217, 239, 327, 481, 557, 703, and~789.
\U section~8.\fi

\M171. The procedure $\\{flush\_list}(\|p)$ frees an entire linked list of
one-word nodes that starts at a given position, until coming to a pointer
that is not in the one-word region. Another procedure,
\\{flush\_node\_list}, frees an entire linked list of one-word and two-word
nodes, until coming to a \\{null} pointer;

\Y\P\4\&{procedure}\1\  \37$\\{flush\_list}(\|p:\\{pointer})$;\C{makes list of
single-word nodes 	available}\6
\4\&{var} \37\|q: \37\\{pointer};\C{the successor of node \|p}\2\6
\&{begin} \37\&{while} $\|p\G\\{second\_mem}$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\\{free\_avail}(\|p)$;\5
$\|p\K\|q$;\6
\&{end};\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{flush\_node\_list}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the node being recycled}\2\6
\&{begin} \37\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{link}(\|p)$;\6
\&{if} $\|q<\\{hi\_mem\_base}$ \1\&{then}\5
$\\{free\_node}(\|q,\392)$\ \&{else} $\\{free\_avail}(\|q)$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M172. If \TeX\ is extended improperly, the \\{mem} array might get screwed up.
For example, some pointers might be wrong, or some ``dead'' nodes might not
have been freed when the last reference to them disappeared. Procedures
\\{check\_mem} and \\{search\_mem} are available to help diagnose such
problems. These procedures make use of two arrays called \\{free} and
\\{was\_free} that are present only if \TeX's debugging routines have
been included. (You may want to decrease the size of \\{mem} while you
are debugging; decreasing \\{mem\_max} saves space and time,
and decreasing \\{hi\_mem\_base} saves time.)

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{debug} \37\\{free}: \37\&{packed} \37\&{array} $[\\{mem\_base}\to\\{mem%
\_max}]$ \1\&{of}\5
\\{boolean};\C{free cells}\2\6
\4\hbox{\hskip1em}\\{was\_free}: \37\&{packed} \37\&{array} $[\\{mem\_base}\to%
\\{mem\_max}]$ \1\&{of}\5
\\{boolean};\C{previously free cells}\2\6
\4\hbox{\hskip1em}\\{was\_mem\_end}: \37\\{pointer};\C{previous \\{mem\_end}}\6
\4\hbox{\hskip1em}\\{panicking}: \37\\{boolean};\C{do we want to check memory
constantly?}\6
\&{gubed}\par
\fi

\M173. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{debug} \37$\\{was\_mem\_end}\K\\{mem\_base}$;\C{indicate that everything was
previously free}\6
$\\{panicking}\K\\{false}$;\6
\&{gubed}\par
\fi

\M174. Procedure \\{check\_mem} makes sure that the available space lists of
\\{mem} are well formed, and it optionally prints out all locations
that are reserved now but were free the last time this procedure was called.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{check\_mem}(\\{print\_locs}:%
\\{boolean})$;\6
\4\&{label} \37$\\{done1},\39\\{done2}$;\C{loop exits}\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{current locations of interest in %
\\{mem}}\6
\\{clobbered}: \37\\{boolean};\C{is something amiss?}\2\6
\&{begin} \37\&{for} $\|p\K\\{mem\_base}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{free}[\|p]\K\\{false}$;\C{you can probably 	do this faster}\2\6
\X175:Check single-word \\{avail} list\X;\6
\X176:Check variable-size \\{avail} list\X;\6
\X177:Check flags of unavailable nodes\X;\6
\&{if} $\\{print\_locs}$ \1\&{then}\5
\X178:Print newly busy locations\X;\2\6
\&{for} $\|p\K0\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{was\_free}[\|p]\K\\{free}[\|p]$;\C{$\\{was\_free}\K\\{free}$ might be
faster}\2\6
$\\{was\_mem\_end}\K\\{mem\_end}$;\6
\&{end};\6
\&{gubed}\par
\fi

\M175. \P$\X175:Check single-word \\{avail} list\X\S$\6
$\|p\K\\{avail}$;\5
$\|q\K\\{null}$;\5
$\\{clobbered}\K\\{false}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $(\|p>\\{mem\_end})\V(\|p<\\{second\_mem})$ \1\&{then}\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $\\{free}[\|p]$ \1\&{then}\5
$\\{clobbered}\K\\{true}$;\2\2\6
\&{if} $\\{clobbered}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"AVAIL\ list\ clobbered\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done1};\6
\&{end};\2\6
$\\{free}[\|p]\K\\{true}$;\5
$\|q\K\|p$;\5
$\|p\K\\{link}(\|q)$;\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~174.\fi

\M176. \P$\X176:Check variable-size \\{avail} list\X\S$\6
$\|p\K\\{rover}$;\5
$\|q\K\\{null}$;\5
$\\{clobbered}\K\\{false}$;\6
\1\&{repeat} \37\&{if} $(\|p\G\\{hi\_mem\_base})\V(\|p<\\{first\_mem})$ \1%
\&{then}\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $(\\{rlink}(\|p)\G\\{hi\_mem\_base})\V(\\{rlink}(\|p)<%
\\{first\_mem})$ \1\&{then}\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $\R(\\{is\_empty}(\|p))\V(\\{node\_size}(\|p)<2)\V\30(\|p+%
\\{node\_size}(\|p)>\\{hi\_mem\_base})\V\30(\\{llink}(\\{rlink}(\|p))\I\|p)$ \1%
\&{then}\5
$\\{clobbered}\K\\{true}$;\2\2\2\6
\&{if} $\\{clobbered}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Double-AVAIL\ list\ clobbered\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done2};\6
\&{end};\2\6
\&{for} $\|q\K\|p\mathrel{\&{to}}\|p+\\{node\_size}(\|p)-1$ \1\&{do}\C{mark all
locations free}\6
\&{begin} \37\&{if} $\\{free}[\|q]$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Doubly\ free\ location\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done2};\6
\&{end};\2\6
$\\{free}[\|q]\K\\{true}$;\6
\&{end};\2\6
$\|q\K\|p$;\5
$\|p\K\\{rlink}(\|p)$;\6
\4\&{until}\5
$\|p=\\{rover}$;\2\6
\4\\{done2}: \37\par
\U section~174.\fi

\M177. \P$\X177:Check flags of unavailable nodes\X\S$\6
$\|p\K\\{mem\_base}$;\6
\&{while} $\|p\L\\{hi\_mem\_base}$ \1\&{do}\C{node \|p should not be empty}\6
\&{begin} \37\&{if} $\\{is\_empty}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Bad\ flag\ at\ "})$;\5
$\\{print\_int}(\|p)$;\6
\&{end};\2\6
\&{while} $(\|p\L\\{hi\_mem\_base})\W\R\\{free}[\|p]$ \1\&{do}\5
$\\{incr}(\|p)$;\2\6
\&{while} $(\|p\L\\{hi\_mem\_base})\W\\{free}[\|p]$ \1\&{do}\5
$\\{incr}(\|p)$;\2\6
\&{end}\2\par
\U section~174.\fi

\M178. \P$\X178:Print newly busy locations\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{"New\ busy\ locs:"})$;\6
\&{for} $\|p\K\\{mem\_base}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\6
\&{if} $\R\\{free}[\|p]\W((\|p>\\{was\_mem\_end})\V\\{was\_free}[\|p])$ \1%
\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\|p)$;\6
\&{end};\2\2\6
\&{end}\par
\U section~174.\fi

\M179. The \\{search\_mem} procedure attempts to answer the question ``Who
points
to node~\|p?'' In doing so, it fetches \\{link} and \\{info} fields of \\{mem}
that might not be of type \\{two\_halves}. Strictly speaking, this is
undefined in \PASCAL, and it can lead to ``false drops'' (words that seem to
point to \|p purely by coincidence). But for debugging purposes, we want
to rule out the places that do {\sl not\/} point to \|p, so a few false
drops are tolerable.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{search\_mem}(\|p:\\{pointer})$;%
\C{look for pointers to \|p}\6
\4\&{var} \37\|q: \37\\{integer};\C{current position being searched}\2\6
\&{begin} \37\&{for} $\|q\K\\{mem\_base}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{link}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"LINK("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{if} $\\{info}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"INFO("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end};\2\6
\X197:Search \\{eqtb} for equivalents equal to \|p\X;\6
\&{end};\6
\&{gubed}\par
\fi

\N180.  \[12] The command codes.
Before we can go much further, we need to define symbolic names for the
internal
code numbers that represent the various commands obeyed by \MF. These codes
are somewhat arbitrary, but not completely so. For example,
some codes have been made adjacent so that   \&{case}  statements in the
program need not consider cases that are widely spaced, or so that   \&{case}
statements can be replaced by   \&{if}  statements.

At any rate, here is the list, for future reference.

\Y\P\D \37$\\{input}=1$\C{input a source file (\&{input}, \&{endinput})}\par
\P\D \37$\\{if\_test}=2$\C{conditional text (\&{if})}\par
\P\D \37$\\{fi\_or\_else}=3$\C{delimiters for conditionals (\&{elseif}, %
\&{else}, \&{fi}}\par
\P\D \37$\\{loop\_repeat}=4$\C{delimiters for loops (\&{loop}, \&{endloop}}\par
\P\D \37$\\{defined\_macro}=5$\C{a macro defined by the user}\par
\P\D \37$\\{min\_command}=\\{defined\_macro}+1$\par
\P\D \37$\\{relax}=6$\C{do nothing (\&{relax})}\par
\P\D \37$\\{type\_name}=7$\C{declare a type (\&{numeric}, \&{pair}, etc.}\par
\P\D \37$\\{max\_statement\_command}=\\{type\_name}$\par
\P\D \37$\\{min\_primary\_command}=\\{type\_name}$\par
\P\D \37$\\{left\_delimiter}=8$\C{the left delimiter of a matching pair}\par
\P\D \37$\\{begin\_group}=9$\C{beginning of a group (\&{begingroup})}\par
\P\D \37$\\{boolean\_const}=10$\C{a boolean constant (\&{true}, \&{false})}\par
\P\D \37$\\{numeric\_token}=11$\C{a numeric constant (e.g., \.{3.14159})}\par
\P\D \37$\\{string\_token}=12$\C{a string constant (e.g., \.{"hello"})}\par
\P\D \37$\\{nullary}=13$\C{an operator without arguments (e.g., %
\&{normaldeviate})}\par
\P\D \37$\\{unary}=14$\C{an operator with one argument (e.g., \&{sqrt})}\par
\P\D \37$\\{primary\_binary}=15$\C{binary operation taking `\&{of}' (e.g., %
\&{cull})}\par
\P\D \37$\\{internal\_quantity}=16$\C{internal numeric parameter (e.g., %
\&{pausing})}\par
\P\D \37$\\{expr\_arg}=17$\C{expression argument from a macro expansion}\par
\P\D \37$\\{name\_token}=18$\C{a symbolic token without a primitive meaning}\par
\P\D \37$\\{plus\_or\_minus}=19$\C{either `\.+' or `\.-'}\par
\P\D \37$\\{max\_primary\_command}=\\{plus\_or\_minus}$\par
\P\D \37$\\{min\_tertiary\_command}=\\{plus\_or\_minus}$\par
\P\D \37$\\{tertiary\_secondary\_macro}=20$\C{a macro defined by %
\&{secondarydef}}\par
\P\D \37$\\{tertiary\_binary}=21$\C{an operator at the tertiary level (e.g., `%
\.{++}')}\par
\P\D \37$\\{ampersand}=22$\C{the operator `\.\&'}\par
\P\D \37$\\{max\_tertiary\_command}=\\{ampersand}$\par
\P\D \37$\\{min\_expression\_command}=\\{ampersand}$\par
\P\D \37$\\{path\_join}=23$\C{the operator `\.{..}'}\par
\P\D \37$\\{expression\_tertiary\_macro}=24$\C{a macro defined by %
\&{tertiarydef}}\par
\P\D \37$\\{expression\_binary}=24$\C{an operator at the expression level
(e.g., `.<')}\par
\P\D \37$\\{equals}=25$\C{the operator `\.='}\par
\P\D \37$\\{max\_expression\_command}=\\{equals}$\par
\P\D \37$\\{and\_command}=26$\C{the operator `\&{and}'}\par
\P\D \37$\\{min\_secondary\_command}=\\{and\_command}$\par
\P\D \37$\\{left\_bracket}=27$\C{the operator `\.['}\par
\P\D \37$\\{secondary\_primary\_macro}=28$\C{a macro defined by \&{primarydef}}%
\par
\P\D \37$\\{slash}=29$\C{the operator `\./'}\par
\P\D \37$\\{secondary\_binary}=30$\C{an operator at the binary level (e.g., %
\&{shifted})}\par
\P\D \37$\\{max\_secondary\_command}=\\{secondary\_binary}$\par
\P\D \37$\\{save\_command}=31$\C{save a list of tokens (\&{save})}\par
\P\D \37$\\{interim\_command}=32$\C{save an internal quantity (\&{interim})}\par
\P\D \37$\\{let\_command}=33$\C{redefine a symbolic token (\&{let})}\par
\P\D \37$\\{macro\_def}=34$\C{define a macro (\&{def}, \&{vardef}, etc.)}\par
\P\D \37$\\{iteration}=35$\C{iterate (\&{for}, \&{forsuffixes}, \&{endfor})}\par
\P\D \37$\\{ship\_out\_command}=36$\C{output a character (\&{shipout})}\par
\P\D \37$\\{drawing\_command}=37$\C{add to edges (\&{addto})}\par
\P\D \37$\\{labeling\_command}=38$\C{output a label (\&{toplabel}, etc.)}\par
\P\D \37$\\{protection\_command}=39$\C{set protection flag (\&{outer}, %
\&{inner})}\par
\P\D \37$\\{show\_command}=40$\C{diagnostic output (\&{show}, \&{showvar},
etc.)}\par
\P\D \37$\\{mode\_command}=41$\C{set iteraction level (\&{batchmode}, etc.)}\par
\P\D \37$\\{report\_stats}=42$\C{show memory usage (\&{reportstats})}\par
\P\D \37$\\{random\_seed}=43$\C{initialize random number generator (%
\&{randomseed})}\par
\P\D \37$\\{message\_command}=44$\C{communicate to user (\&{message}, %
\&{errmessage})}\par
\P\D \37$\\{every\_job\_command}=45$\C{designate a starting token (%
\&{everyjob})}\par
\P\D \37$\\{delimiters}=46$\C{define a pair of delimiters (\&{delimiters})}\par
\P\D \37$\\{open\_window}=47$\C{define a window on the screen (\&{openwindow})}%
\par
\P\D \37$\\{end\_read\_terminal}=48$\C{a \&{readterminal} line has ended}\par
\P\D \37$\\{param\_level}=49$\C{either \&{primary}, \&{secondary}, or %
\&{tertiary}}\par
\P\D \37$\\{controls}=50$\C{specify control points explicitly (\&{controls})}%
\par
\P\D \37$\\{tension}=51$\C{specify tension between knots (\&{tension})}\par
\P\D \37$\\{cycle}=52$\C{close a cyclic path (\&{cycle})}\par
\P\D \37$\\{curl\_command}=53$\C{specify curl at an end knot (\&{curl})}\par
\P\D \37$\\{right\_delimiter}=54$\C{the right delimiter of a matching pair}\par
\P\D \37$\\{right\_bracket}=55$\C{the operator `\.]'}\par
\P\D \37$\\{right\_brace}=56$\C{the operator `\.{\char`\}}'}\par
\P\D \37$\\{left\_brace}=57$\C{the operator `\.{\char`\{}'}\par
\P\D \37$\\{of\_token}=58$\C{the operator `\&{of}'}\par
\P\D \37$\\{as\_token}=59$\C{the operator `\&{as}'}\par
\P\D \37$\\{from\_token}=60$\C{the operator `\&{from}'}\par
\P\D \37$\\{to\_token}=61$\C{the operator `\&{to}'}\par
\P\D \37$\\{at\_token}=62$\C{the operator `\&{at}'}\par
\P\D \37$\\{until\_token}=63$\C{the operator `\&{until}'}\par
\P\D \37$\\{colon}=64$\C{the operator `\.:'}\par
\P\D \37$\\{assignment}=65$\C{the operator `\.{:=}'}\par
\P\D \37$\\{comma}=66$\C{the operator `\.,'}\par
\P\D \37$\\{semicolon}=67$\C{the operator `\.;'}\par
\P\D \37$\\{end\_group}=68$\C{end a group (\&{endgroup})}\par
\P\D \37$\\{stop}=69$\C{end a job (\&{end}, \&{dump})}\par
\fi

\M181. Variables and capsules in \MF\ have a variety of ``types,''
distinguished by the following code numbers:

\Y\P\D \37$\\{undefined}=0$\par
\P\D \37$\\{vacuous}=1$\par
\P\D \37$\\{boolean\_type}=2$\par
\P\D \37$\\{unknown\_boolean}=3$\par
\P\D \37$\\{string\_type}=4$\par
\P\D \37$\\{unknown\_string}=5$\par
\P\D \37$\\{pen\_type}=6$\par
\P\D \37$\\{unknown\_pen}=7$\par
\P\D \37$\\{future\_pen}=8$\par
\P\D \37$\\{edges\_type}=9$\par
\P\D \37$\\{unknown\_edges}=10$\par
\P\D \37$\\{path\_type}=11$\par
\P\D \37$\\{unknown\_path}=12$\par
\P\D \37$\\{transform\_type}=13$\par
\P\D \37$\\{pair\_type}=14$\par
\P\D \37$\\{known}=15$\par
\P\D \37$\\{dependent}=16$\par
\P\D \37$\\{proto\_dependent}=17$\par
\P\D \37$\\{numeric\_type}=18$\par
\P\D \37$\\{independent}=19$\par
\P\D \37$\\{token\_list}=20$\par
\P\D \37$\\{structured}=21$\par
\P\D \37$\\{unsuffixed\_macro}=22$\par
\P\D \37$\\{suffixed\_macro}=23$\par
\Y\P\4\&{procedure}\1\  \37$\\{print\_type}(\|t:\\{small\_number})$;\2\6
\&{begin} \37\&{case} $\|t$ \1\&{of}\6
\4\\{vacuous}: \37$\\{print}(\.{"vacuous"})$;\6
\4\\{boolean\_type}: \37$\\{print}(\.{"boolean"})$;\6
\4\\{unknown\_boolean}: \37$\\{print}(\.{"unknown\ boolean"})$;\6
\4\\{string\_type}: \37$\\{print}(\.{"string"})$;\6
\4\\{unknown\_string}: \37$\\{print}(\.{"unknown\ string"})$;\6
\4\\{pen\_type}: \37$\\{print}(\.{"pen"})$;\6
\4\\{unknown\_pen}: \37$\\{print}(\.{"unknown\ pen"})$;\6
\4\\{future\_pen}: \37$\\{print}(\.{"future\ pen"})$;\6
\4\\{edges\_type}: \37$\\{print}(\.{"edges"})$;\6
\4\\{unknown\_edges}: \37$\\{print}(\.{"unknown\ edges"})$;\6
\4\\{path\_type}: \37$\\{print}(\.{"path"})$;\6
\4\\{unknown\_path}: \37$\\{print}(\.{"unknown\ path"})$;\6
\4\\{transform\_type}: \37$\\{print}(\.{"transform"})$;\6
\4\\{pair\_type}: \37$\\{print}(\.{"pair"})$;\6
\4\\{known}: \37$\\{print}(\.{"known"})$;\6
\4\\{dependent}: \37$\\{print}(\.{"dependent"})$;\6
\4\\{proto\_dependent}: \37$\\{print}(\.{"proto-dependent"})$;\6
\4\\{numeric\_type}: \37$\\{print}(\.{"numeric"})$;\6
\4\\{independent}: \37$\\{print}(\.{"independent"})$;\6
\4\\{token\_list}: \37$\\{print}(\.{"token\ list"})$;\6
\4\\{structured}: \37$\\{print}(\.{"structured"})$;\6
\4\\{unsuffixed\_macro}: \37$\\{print}(\.{"unsuffixed\ macro"})$;\6
\4\\{suffixed\_macro}: \37$\\{print}(\.{"suffixed\ macro"})$;\6
\4\&{othercases} \37$\\{print}(\.{"undefined"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M182. Primitive operations that produce values have a secondary identification
code in addition to their command code; it's something like genera and species.
For example, `\.*' has the command code \\{primary\_binary}, and its
secondary identification is \\{times}. The secondary codes start at 30 so that
they don't overlap with the type codes; some type codes (e.g., \\{string%
\_type})
are used as operators as well as type identifications.

\Y\P\D \37$\\{job\_name\_op}=30$\C{operation code for \&{jobname}}\par
\P\D \37$\\{read\_string\_op}=31$\C{operation code for \&{readstring}}\par
\P\D \37$\\{pen\_circle}=32$\C{operation code for \&{pencircle}}\par
\P\D \37$\\{normal\_deviate}=33$\C{operation code for \&{normaldeviate}}\par
\P\D \37$\\{odd\_op}=34$\C{operation code for \&{odd}}\par
\P\D \37$\\{unknown}=35$\C{operation code for \&{unknown}}\par
\P\D \37$\\{not\_op}=36$\C{operation code for \&{not}}\par
\P\D \37$\\{decimal}=37$\C{operation code for \&{decimal}}\par
\P\D \37$\\{reverse}=38$\C{operation code for \&{reverse}}\par
\P\D \37$\\{make\_pen\_op}=39$\C{operation code for \&{makepen}}\par
\P\D \37$\\{oct\_op}=40$\C{operation code for \&{oct}}\par
\P\D \37$\\{hex\_op}=41$\C{operation code for \&{hex}}\par
\P\D \37$\\{ord\_op}=42$\C{operation code for \&{ord}}\par
\P\D \37$\\{char\_op}=43$\C{operation code for \&{char}}\par
\P\D \37$\\{length\_op}=44$\C{operation code for \&{length}}\par
\P\D \37$\\{x\_part}=45$\C{operation code for \&{xpart}}\par
\P\D \37$\\{y\_part}=46$\C{operation code for \&{ypart}}\par
\P\D \37$\\{xx\_part}=47$\C{operation code for \&{xxpart}}\par
\P\D \37$\\{xy\_part}=48$\C{operation code for \&{xypart}}\par
\P\D \37$\\{yx\_part}=49$\C{operation code for \&{yxpart}}\par
\P\D \37$\\{yy\_part}=50$\C{operation code for \&{yypart}}\par
\P\D \37$\\{sqrt\_op}=51$\C{operation code for \&{sqrt}}\par
\P\D \37$\\{m\_exp\_op}=52$\C{operation code for \&{mexp}}\par
\P\D \37$\\{m\_log\_op}=53$\C{operation code for \&{mlog}}\par
\P\D \37$\\{sin\_d\_op}=54$\C{operation code for \&{sind}}\par
\P\D \37$\\{cos\_d\_op}=55$\C{operation code for \&{cosd}}\par
\P\D \37$\\{trunc\_op}=56$\C{operation code for \&{trunc}}\par
\P\D \37$\\{uniform\_deviate}=57$\C{operation code for \&{uniformdeviate}}\par
\P\D \37$\\{arctan\_d\_op}=58$\C{operation code for \&{arctand}}\par
\P\D \37$\\{plus}=59$\C{operation code for \.+}\par
\P\D \37$\\{minus}=60$\C{operation code for \.-}\par
\P\D \37$\\{times}=61$\C{operation code for \.*}\par
\P\D \37$\\{over}=62$\C{operation code for \./}\par
\P\D \37$\\{pythag}=63$\C{operation code for \.{++}}\par
\P\D \37$\\{and\_op}=64$\C{operation code for \&{and}}\par
\P\D \37$\\{or\_op}=65$\C{operation code for \&{or}}\par
\P\D \37$\\{less\_than}=66$\C{operation code for \.<}\par
\P\D \37$\\{less\_or\_equal}=67$\C{operation code for \.{<=}}\par
\P\D \37$\\{greater\_than}=68$\C{operation code for \.>}\par
\P\D \37$\\{greater\_or\_equal}=69$\C{operation code for \.{>=}}\par
\P\D \37$\\{equal\_to}=70$\C{operation code for \.=}\par
\P\D \37$\\{unequal\_to}=71$\C{operation code for \.{<>}}\par
\P\D \37$\\{substring\_of}=72$\C{operation code for \&{substring}}\par
\P\D \37$\\{subpath\_of}=73$\C{operation code for \&{subpath}}\par
\P\D \37$\\{cull\_of}=74$\C{operation code for \&{cull}}\par
\P\D \37$\\{direction\_time\_of}=75$\C{operation code for \&{directiontime}}\par
\P\D \37$\\{point\_of}=76$\C{operation code for \&{point}}\par
\P\D \37$\\{direction\_of}=77$\C{operation code for \&{direction}}\par
\P\D \37$\\{precontrol\_of}=78$\C{operation code for \&{precontrol}}\par
\P\D \37$\\{postcontrol\_of}=79$\C{operation code for \&{postcontrol}}\par
\P\D \37$\\{penoffset\_of}=80$\C{operation code for \&{penoffset}}\par
\P\D \37$\\{concatenate}=81$\C{operation code for \.\&}\par
\P\D \37$\\{union}=82$\C{operation code for \&{union}}\par
\P\D \37$\\{rotated\_by}=83$\C{operation code for \&{rotated}}\par
\P\D \37$\\{slanted\_by}=84$\C{operation code for \&{slanted}}\par
\P\D \37$\\{scaled\_by}=85$\C{operation code for \&{scaled}}\par
\P\D \37$\\{shifted\_by}=86$\C{operation code for \&{shifted}}\par
\P\D \37$\\{transformed\_by}=87$\C{operation code for \&{transformed}}\par
\P\D \37$\\{x\_mult}=88$\C{operation code for \&{xmult}}\par
\P\D \37$\\{y\_mult}=89$\C{operation code for \&{ymult}}\par
\P\D \37$\\{z\_mult}=90$\C{operation code for \&{zmult}}\par
\P\D \37$\\{intersect}=91$\C{operation code for \&{intersect}}\par
\Y\P\4\&{procedure}\1\  \37$\\{print\_op}(\|c:\\{quarterword})$;\2\6
\&{begin} \37\&{if} $\|c\L\\{numeric\_type}$ \1\&{then}\5
$\\{print\_type}(\|c)$\6
\4\&{else} \&{case} $\|c$ \1\&{of}\6
\4\\{job\_name\_op}: \37$\\{print}(\.{"jobname"})$;\6
\4\\{read\_string\_op}: \37$\\{print}(\.{"readstring"})$;\6
\4\\{pen\_circle}: \37$\\{print}(\.{"pencircle"})$;\6
\4\\{normal\_deviate}: \37$\\{print}(\.{"normaldeviate"})$;\6
\4\\{odd\_op}: \37$\\{print}(\.{"odd"})$;\6
\4\\{unknown}: \37$\\{print}(\.{"unknown"})$;\6
\4\\{not\_op}: \37$\\{print}(\.{"not"})$;\6
\4\\{decimal}: \37$\\{print}(\.{"decimal"})$;\6
\4\\{reverse}: \37$\\{print}(\.{"reverse"})$;\6
\4\\{make\_pen\_op}: \37$\\{print}(\.{"makepen"})$;\6
\4\\{oct\_op}: \37$\\{print}(\.{"oct"})$;\6
\4\\{hex\_op}: \37$\\{print}(\.{"hex"})$;\6
\4\\{ord\_op}: \37$\\{print}(\.{"ord"})$;\6
\4\\{char\_op}: \37$\\{print}(\.{"char"})$;\6
\4\\{length\_op}: \37$\\{print}(\.{"length"})$;\6
\4\\{x\_part}: \37$\\{print}(\.{"xpart"})$;\6
\4\\{y\_part}: \37$\\{print}(\.{"ypart"})$;\6
\4\\{xx\_part}: \37$\\{print}(\.{"xxpart"})$;\6
\4\\{xy\_part}: \37$\\{print}(\.{"xypart"})$;\6
\4\\{yx\_part}: \37$\\{print}(\.{"yxpart"})$;\6
\4\\{yy\_part}: \37$\\{print}(\.{"yypart"})$;\6
\4\\{sqrt\_op}: \37$\\{print}(\.{"sqrt"})$;\6
\4\\{m\_exp\_op}: \37$\\{print}(\.{"mexp"})$;\6
\4\\{m\_log\_op}: \37$\\{print}(\.{"mlog"})$;\6
\4\\{sin\_d\_op}: \37$\\{print}(\.{"sind"})$;\6
\4\\{cos\_d\_op}: \37$\\{print}(\.{"cosd"})$;\6
\4\\{trunc\_op}: \37$\\{print}(\.{"trunc"})$;\6
\4\\{uniform\_deviate}: \37$\\{print}(\.{"uniformdeviate"})$;\6
\4\\{arctan\_d\_op}: \37$\\{print}(\.{"arctand"})$;\6
\4\\{plus}: \37$\\{print\_char}(\.{"+"})$;\6
\4\\{minus}: \37$\\{print\_char}(\.{"-"})$;\6
\4\\{times}: \37$\\{print\_char}(\.{"*"})$;\6
\4\\{over}: \37$\\{print\_char}(\.{"/"})$;\6
\4\\{pythag}: \37$\\{print}(\.{"++"})$;\6
\4\\{and\_op}: \37$\\{print}(\.{"and"})$;\6
\4\\{or\_op}: \37$\\{print}(\.{"or"})$;\6
\4\\{less\_than}: \37$\\{print\_char}(\.{"<"})$;\6
\4\\{less\_or\_equal}: \37$\\{print}(\.{"<="})$;\6
\4\\{greater\_than}: \37$\\{print\_char}(\.{">"})$;\6
\4\\{greater\_or\_equal}: \37$\\{print}(\.{">="})$;\6
\4\\{equal\_to}: \37$\\{print\_char}(\.{"="})$;\6
\4\\{unequal\_to}: \37$\\{print}(\.{"<>"})$;\6
\4\\{substring\_of}: \37$\\{print}(\.{"substring"})$;\6
\4\\{subpath\_of}: \37$\\{print}(\.{"subpath"})$;\6
\4\\{cull\_of}: \37$\\{print}(\.{"cull"})$;\6
\4\\{direction\_time\_of}: \37$\\{print}(\.{"directiontime"})$;\6
\4\\{point\_of}: \37$\\{print}(\.{"point"})$;\6
\4\\{direction\_of}: \37$\\{print}(\.{"direction"})$;\6
\4\\{precontrol\_of}: \37$\\{print}(\.{"precontrol"})$;\6
\4\\{postcontrol\_of}: \37$\\{print}(\.{"postcontrol"})$;\6
\4\\{penoffset\_of}: \37$\\{print}(\.{"penoffset"})$;\6
\4\\{concatenate}: \37$\\{print}(\.{"\&"})$;\6
\4\\{union}: \37$\\{print}(\.{"union"})$;\6
\4\\{rotated\_by}: \37$\\{print}(\.{"rotated"})$;\6
\4\\{slanted\_by}: \37$\\{print}(\.{"slanted"})$;\6
\4\\{scaled\_by}: \37$\\{print}(\.{"scaled"})$;\6
\4\\{shifted\_by}: \37$\\{print}(\.{"shifted"})$;\6
\4\\{transformed\_by}: \37$\\{print}(\.{"transformed"})$;\6
\4\\{x\_mult}: \37$\\{print}(\.{"xmult"})$;\6
\4\\{y\_mult}: \37$\\{print}(\.{"ymult"})$;\6
\4\\{z\_mult}: \37$\\{print}(\.{"zmult"})$;\6
\4\&{othercases} \37$\\{print}(\.{"intersect"})$\2\6
\&{endcases};\2\6
\&{end};\par
\fi

\M183. \MF\ also has a bunch of internal parameters that a user might want to
fuss with. Every such parameter has an identifying code number, defined here.

\Y\P\D \37$\\{tracing\_titles}=1$\C{show titles on screen when they appear}\par
\P\D \37$\\{tracing\_equations}=2$\C{show each variable when it becomes known}%
\par
\P\D \37$\\{tracing\_choices}=3$\C{show the control points chosen for paths}\par
\P\D \37$\\{tracing\_specs}=4$\C{show subdivision of paths into octants before
digitizing}\par
\P\D \37$\\{tracing\_pens}=5$\C{show details of pens that are made}\par
\P\D \37$\\{tracing\_commands}=6$\C{show commands and operations before they
are performed}\par
\P\D \37$\\{tracing\_macros}=7$\C{show macros before they are expanded}\par
\P\D \37$\\{tracing\_edges}=8$\C{show digitized edges as they are computed}\par
\P\D \37$\\{tracing\_stats}=9$\C{show memory usage}\par
\P\D \37$\\{tracing\_online}=10$\C{show long diagnostics on terminal and in the
log file}\par
\P\D \37$\\{year}=11$\C{the current year (e.g., 1984)}\par
\P\D \37$\\{month}=12$\C{the current month (e.g, 3 $\equiv$ March)}\par
\P\D \37$\\{day}=13$\C{the current day of the month}\par
\P\D \37$\\{time}=14$\C{the number of minutes since midnight when this job
started}\par
\P\D \37$\\{char\_code}=15$\C{the number of the next character to be output}\par
\P\D \37$\\{char\_wd}=16$\C{the width of the next character to be output}\par
\P\D \37$\\{char\_ht}=17$\C{the height of the next character to be output}\par
\P\D \37$\\{char\_dp}=18$\C{the depth of the next character to be output}\par
\P\D \37$\\{char\_ic}=19$\C{the italic correction of the next character to be
output}\par
\P\D \37$\\{char\_dw}=20$\C{the device width of the next character, in pixels}%
\par
\P\D \37$\\{design\_size}=21$\C{the unit of measure used for $\\{char\_wd}\to%
\\{char\_ic}$, in points}\par
\P\D \37$\\{ppp}=22$\C{the number of pixels per point}\par
\P\D \37$\\{label\_factor}=23$\C{the size of label characters, in pixels}\par
\P\D \37$\\{pausing}=24$\C{if positive, pause after each line is read for a
file}\par
\P\D \37$\\{labeling}=25$\C{if positive, labels will be computed and output}\par
\P\D \37$\\{proofing}=26$\C{positive for proof mode, negative to suppress
output}\par
\P\D \37$\\{max\_internal}=\\{proofing}$\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{internal}: \37\&{array} $[0\to\\{max\_internal}]$ \1\&{of}\5
\\{integer};\C{the values of internal quantities}\2\par
\fi

\M184. The symbolic names for internal quantities are put into \MF's hash table
by using the routine called \\{primitive}, defined below. Let us enter them
now, so that we don't have to list all those names anywhere else.

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\S$\6
$\\{primitive}(\.{"tracingtitles"},\39\\{internal\_quantity},\39\\{tracing%
\_titles})$;\6
$\\{primitive}(\.{"tracingequations"},\39\\{internal\_quantity},\39\\{tracing%
\_equations})$;\6
$\\{primitive}(\.{"tracingchoices"},\39\\{internal\_quantity},\39\\{tracing%
\_choices})$;\6
$\\{primitive}(\.{"tracingspecs"},\39\\{internal\_quantity},\39\\{tracing%
\_specs})$;\6
$\\{primitive}(\.{"tracingpens"},\39\\{internal\_quantity},\39\\{tracing%
\_pens})$;\6
$\\{primitive}(\.{"tracingcommands"},\39\\{internal\_quantity},\39\\{tracing%
\_commands})$;\6
$\\{primitive}(\.{"tracingmacros"},\39\\{internal\_quantity},\39\\{tracing%
\_macros})$;\6
$\\{primitive}(\.{"tracingedges"},\39\\{internal\_quantity},\39\\{tracing%
\_edges})$;\6
$\\{primitive}(\.{"tracingstats"},\39\\{internal\_quantity},\39\\{tracing%
\_stats})$;\6
$\\{primitive}(\.{"tracingonline"},\39\\{internal\_quantity},\39\\{tracing%
\_online})$;\6
$\\{primitive}(\.{"year"},\39\\{internal\_quantity},\39\\{year})$;\6
$\\{primitive}(\.{"month"},\39\\{internal\_quantity},\39\\{month})$;\6
$\\{primitive}(\.{"day"},\39\\{internal\_quantity},\39\\{day})$;\6
$\\{primitive}(\.{"time"},\39\\{internal\_quantity},\39\\{time})$;\6
$\\{primitive}(\.{"charcode"},\39\\{internal\_quantity},\39\\{char\_code})$;\6
$\\{primitive}(\.{"charwd"},\39\\{internal\_quantity},\39\\{char\_wd})$;\6
$\\{primitive}(\.{"charht"},\39\\{internal\_quantity},\39\\{char\_ht})$;\6
$\\{primitive}(\.{"chardp"},\39\\{internal\_quantity},\39\\{char\_dp})$;\6
$\\{primitive}(\.{"charic"},\39\\{internal\_quantity},\39\\{char\_ic})$;\6
$\\{primitive}(\.{"chardw"},\39\\{internal\_quantity},\39\\{char\_dw})$;\6
$\\{primitive}(\.{"designsize"},\39\\{internal\_quantity},\39\\{design%
\_size})$;\6
$\\{primitive}(\.{"ppp"},\39\\{internal\_quantity},\39\\{ppp})$;\6
$\\{primitive}(\.{"labelfactor"},\39\\{internal\_quantity},\39\\{label%
\_factor})$;\6
$\\{primitive}(\.{"pausing"},\39\\{internal\_quantity},\39\\{pausing})$;\6
$\\{primitive}(\.{"labeling"},\39\\{internal\_quantity},\39\\{labeling})$;\6
$\\{primitive}(\.{"proofing"},\39\\{internal\_quantity},\39\\{proofing})$;\par
\A sections~199, 213, 548, 553, 561, 571, 588, 671, 739, 751, and~783.
\U section~815.\fi

\M185. \MF\ is occasionally supposed to print diagnostic information that
goes only into the transcript file, unless \\{tracing\_online} is positive.
Now that we have defined \\{tracing\_online} we can define
two routines that adjust the destination of print commands:

\Y\P\4\&{procedure}\1\  \37\\{begin\_diagnostic};\C{prepare to do some tracing}%
\2\6
\&{begin} \37$\\{old\_setting}\K\\{selector}$;\6
\&{if} $\\{history}=\\{spotless}$ \1\&{then}\5
$\\{history}\K\\{warning\_issued}$;\2\6
\&{if} $(\\{internal}[\\{tracing\_online}]\L0)\W(\\{selector}=\\{term\_and%
\_log})$ \1\&{then}\5
$\\{decr}(\\{selector})$;\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{end\_diagnostic}(\\{blank\_line}:\\{boolean})$;%
\C{restore proper conditions after tracing}\2\6
\&{begin} \37$\\{print\_nl}(\.{""})$;\6
\&{if} $\\{blank\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
$\\{selector}\K\\{old\_setting}$;\6
\&{end};\par
\fi

\M186. Of course we had better declare another global variable, if the previous
routines are going to work.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{old\_setting}: \37$0\to\\{max\_selector}$;\par
\fi

\M187. We will occasionally use \\{begin\_diagnositic} in connection with
line-number
printing, as follows. (The parameter \|s is typically \.{"Path"} or \.{"Cycle\
spec"},
etc.)

\Y\P$\\{print\_diagnostic}(\|s,\39\|t:\\{str\_number})$\1\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\|s)$;\5
$\\{print}(\.{"\ at\ line\ "})$;\5
$\\{print\_int}(\\{line})$;\5
$\\{print}(\|t)$;\5
$\\{print\_char}(\.{":"})$;\6
\&{end};\2\par
\fi

\M188. The 128 \\{ASCII\_code} characters are grouped into classes by means of
the \\{char\_class} table. Individual class numbers have no semantic
or syntactic significance, expect in a few instances defined here.
There's also \\{max\_class}, which can be used as a basis for additional
class numbers in nonstandard extensions of \MF.

\Y\P\D \37$\\{digit\_class}=0$\C{the class number of \.{0123456789}}\par
\P\D \37$\\{period\_class}=1$\C{the class number of `\..'}\par
\P\D \37$\\{space\_class}=2$\C{the class number of spaces and nonstandard
characters}\par
\P\D \37$\\{percent\_class}=3$\C{the class number of `\.\%'}\par
\P\D \37$\\{string\_class}=4$\C{the class number of `\."'}\par
\P\D \37$\\{isolated\_classes}\S5,\396,\397,\398$\C{characters that make
length-one tokens only}\par
\P\D \37$\\{max\_special\_class}=8$\C{the largest syntactically meaningful
class number}\par
\P\D \37$\\{letter\_class}=9$\C{used in typeouts}\par
\P\D \37$\\{left\_bracket\_class}=17$\C{ditto}\par
\P\D \37$\\{right\_bracket\_class}=18$\C{ditto}\par
\P\D \37$\\{max\_class}=19$\C{the largest class number}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{char\_class}: \37\&{array} $[\\{ASCII\_code}]$ \1\&{of}\5
\\{ASCII\_code};\C{the class numbers}\2\par
\fi

\M189. If changes are made to accommodate non-ASCII character sets, they should
follow the guidelines in Appendix~C of {\tenss The \MF book}.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|k\K\.{"0"}\mathrel{\&{to}}\.{"9"}$ \1\&{do}\5
$\\{char\_class}[\|k]\K\\{digit\_class}$;\2\6
$\\{char\_class}[\.{"."}]\K\\{period\_class}$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\.{"\ "}$ \1\&{do}\5
$\\{char\_class}[\|k]\K\\{space\_class}$;\2\6
$\\{char\_class}[127]\K\\{space\_class}$;\6
$\\{char\_class}[\.{"\%"}]\K\\{percent\_class}$;\5
$\\{char\_class}[\.{""}\.{""}]\K\\{string\_class}$;\6
$\\{char\_class}[\.{","}]\K5$;\5
$\\{char\_class}[\.{";"}]\K6$;\5
$\\{char\_class}[\.{"("}]\K7$;\5
$\\{char\_class}[\.{")"}]\K8$;\6
\&{for} $\|k\K\.{"A"}\mathrel{\&{to}}\.{"Z"}$ \1\&{do}\5
$\\{char\_class}[\|k]\K\\{letter\_class}$;\2\6
\&{for} $\|k\K\.{"a"}\mathrel{\&{to}}\.{"z"}$ \1\&{do}\5
$\\{char\_class}[\|k]\K\\{letter\_class}$;\2\6
$\\{char\_class}[\.{"\_"}]\K\\{letter\_class}$;\6
$\\{char\_class}[\.{"<"}]\K10$;\5
$\\{char\_class}[\.{"="}]\K10$;\5
$\\{char\_class}[\.{">"}]\K10$;\5
$\\{char\_class}[\.{":"}]\K10$;\5
$\\{char\_class}[\.{"|"}]\K10$;\6
$\\{char\_class}[\.{"\`"}]\K11$;\5
$\\{char\_class}[\.{"\'"}]\K11$;\6
$\\{char\_class}[\.{"+"}]\K12$;\5
$\\{char\_class}[\.{"-"}]\K12$;\6
$\\{char\_class}[\.{"/"}]\K13$;\5
$\\{char\_class}[\.{"*"}]\K13$;\5
$\\{char\_class}[\.{"\\"}]\K13$;\6
$\\{char\_class}[\.{"!"}]\K14$;\5
$\\{char\_class}[\.{"?"}]\K14$;\6
$\\{char\_class}[\.{"\#"}]\K15$;\5
$\\{char\_class}[\.{"\&"}]\K15$;\5
$\\{char\_class}[\.{"@"}]\K15$;\5
$\\{char\_class}[\.{"\$"}]\K15$;\6
$\\{char\_class}[\.{"\↑"}]\K16$;\5
$\\{char\_class}[\.{"\~"}]\K16$;\6
$\\{char\_class}[\.{"["}]\K\\{left\_bracket\_class}$;\5
$\\{char\_class}[\.{"]"}]\K\\{right\_bracket\_class}$;\6
$\\{char\_class}[\.{"\{"}]\K19$;\5
$\\{char\_class}[\.{"\}"}]\K19$;\par
\fi

\N190.  \[xx] The hash table.
Symbolic tokens are stored and retrieved by means of a fairly standard hash
table algorithm called the method of ``coalescing lists'' (cf.\ Algorithm 6.4C
in {\sl The Art of Computer Programming\/}). Once a symbolic token enters the
table, it is never removed.

The actual sequence of characters forming a symbolic token is
stored in the \\{str\_pool} array together with all the other strings. An
auxiliary array \\{hash} consists of items with two halfword fields per
word. The first of these, called $\\{next}(\|p)$, points to the next identifier
belonging to the same coalesced list as the identifier corresponding to~\|p;
and the other, called $\\{text}(\|p)$, points to the \\{str\_start} entry for
\|p's identifier. If position~\|p of the hash table is empty, we have
$\\{text}(\|p)=0$; if position \|p is either empty or the end of a coalesced
hash list, we have $\\{next}(\|p)=0$.

An auxiliary pointer variable called \\{hash\_used} is maintained in such a
way that all locations $\|p\G\\{hash\_used}$ are nonempty. The global variable
\\{st\_count} tells how many symbolic tokens have been defined, if statistics
are being kept.

There's a parallel array called \\{eqtb} that contains the current equivalent
values of each symbolic token. The entries of this array consist of
two halfwords called \\{eq\_type} (a command code) and \\{equiv} (a secondary
piece of information that qualifies the \\{eq\_type}).

\Y\P\D \37$\\{next}(\#)\S\\{hash}[\#].\\{lh}$\C{link for coalesced lists}\par
\P\D \37$\\{text}(\#)\S\\{hash}[\#].\\{rh}$\C{string number for symbolic token
name}\par
\P\D \37$\\{hash\_is\_full}\S(\\{hash\_used}=1)$\C{test if all positions are
occupied}\par
\P\D \37$\\{eq\_type}(\#)\S\\{eqtb}[\#].\\{lh}$\C{the current ``meaning'' of a
symbolic token}\par
\P\D \37$\\{equiv}(\#)\S\\{eqtb}[\#].\\{rh}$\C{parametric part of a token's
meaning}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hash}: \37\&{array} $[1\to\\{hash\_size}]$ \1\&{of}\5
\\{two\_halves};\C{the hash table}\2\6
\4\\{eqtb}: \37\&{array} $[1\to\\{hash\_size}]$ \1\&{of}\5
\\{two\_halves};\C{the equivalents}\2\6
\4\\{hash\_used}: \37\\{pointer};\C{allocation pointer for \\{hash}}\6
\4\\{st\_count}: \37\\{integer};\C{total number of known identifiers}\par
\fi

\M191. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{next}(1)\K0$;\5
$\\{text}(1)\K0$;\5
$\\{eq\_type}(1)\K\\{name\_token}$;\5
$\\{equiv}(1)\K\\{null}$;\6
\&{for} $\|k\K2\mathrel{\&{to}}\\{hash\_size}$ \1\&{do}\6
\&{begin} \37$\\{hash}[\|k]\K\\{hash}[1]$;\5
$\\{eqtb}[\|k]\K\\{eqtb}[1]$;\6
\&{end};\2\par
\fi

\M192. Certain entries in the hash table are ``frozen'' and not redefinable,
since they are used in error recovery. FIXTHIS: Initialize them.

\Y\P\D \37$\\{frozen\_undefined}\S\\{hash\_size}$\C{\\{hash} location that
never gets defined}\par
\P\D \37$\\{frozen\_fi}\S\\{hash\_size}-1$\C{\\{hash} location of a permanent %
\&{fi}}\par
\P\D \37$\\{frozen\_end\_def}\S\\{hash\_size}-2$\C{\\{hash} location of a
permanent \&{enddef}}\par
\P\D \37$\\{frozen\_relax}\S\\{hash\_size}-3$\C{\\{hash} location of a
permanent \&{relax}}\par
\P\D \37$\\{frozen\_end\_loop}\S\\{hash\_size}-4$\C{\\{hash} location of a
permanent \&{endloop}}\par
\P\D \37$\\{frozen\_end\_group}\S\\{hash\_size}-5$\C{\\{hash} location of a
permanent \&{endgroup}}\par
\P\D \37$\\{frozen\_colon}\S\\{hash\_size}-6$\C{\\{hash} location of a
permanent `\.:'}\par
\P\D \37$\\{frozen\_slash}\S\\{hash\_size}-7$\C{\\{hash} location of a
permanent `\./'}\par
\P\D \37$\\{frozen\_left\_bracket}\S\\{hash\_size}-8$\C{\\{hash} location of a
permanent `\.['}\par
\P\D \37$\\{frozen\_inaccessible}\S\\{hash\_size}-9$\C{\\{hash} location to
protect frozen area}\par
\P\D \37$\\{effective\_hash\_size}\S\\{hash\_size}-10$\C{\\{hash\_size} in
published stats}\par
\fi

\M193. \P$\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}%
\S$\6
$\\{hash\_used}\K\\{effective\_hash\_size}+1$;\C{nothing is used}\6
$\\{st\_count}\K0$;\par
\fi

\M194. Here is the subroutine that searches the hash table for an identifier
that matches a given string of length~\|l appearing in $\\{buffer}[\|j\to(\|j+%
\|l-1)]$. If the identifier is not found, it is inserted; hence it
will always be found, and the corresponding hash table address
will be returned.

\Y\P\4\&{function}\1\  \37$\\{id\_lookup}(\|j,\39\|l:\\{integer})$: \37%
\\{pointer};\C{search the hash table}\6
\4\&{label} \37\\{found};\C{go here when you've found it}\6
\4\&{var} \37\|h: \37\\{integer};\C{hash code}\6
\|p: \37\\{pointer};\C{index in \\{hash} array}\6
\|k: \37\\{pointer};\C{index in \\{buffer} array}\2\6
\&{begin} \37\X196:Compute the hash code \|h\X;\6
$\|p\K\|h+1$;\C{we start searching here; note that $0\L\|h<\\{hash\_prime}$}\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{text}(\|p)>0$ \1\&{then}\6
\&{if} $\\{length}(\\{text}(\|p))=\|l$ \1\&{then}\6
\&{if} $\\{str\_eq\_buf}(\\{text}(\|p),\39\|j)$ \1\&{then}\5
\&{goto} \37\\{found};\2\2\2\6
\&{if} $\\{next}(\|p)=0$ \1\&{then}\5
\X195:Insert a new symbolic token after \|p, then make \|p point to it and %
\&{goto} \\{found}\X;\2\6
$\|p\K\\{next}(\|p)$;\6
\&{end};\2\6
\4\\{found}: \37$\\{id\_lookup}\K\|p$;\6
\&{end};\par
\fi

\M195. \P$\X195:Insert a new symbolic token after \|p, then make \|p point to
it and \&{goto} \\{found}\X\S$\6
\&{begin} \37\&{if} $\\{text}(\|p)>0$ \1\&{then}\6
\&{begin} \37\1\&{repeat} \37\&{if} $\\{hash\_is\_full}$ \1\&{then}\5
$\\{overflow}(\.{"hash\ size"},\39\\{effective\_hash\_size})$;\2\6
$\\{decr}(\\{hash\_used})$;\6
\4\&{until}\5
$\\{text}(\\{hash\_used})=0$;\C{search for an empty location in \\{hash}}\2\6
$\\{next}(\|p)\K\\{hash\_used}$;\5
$\|p\K\\{hash\_used}$;\6
\&{end};\2\6
\&{if} $\|l=1$ \1\&{then}\5
$\\{text}(\|p)\K\\{buffer}[\|k]$\6
\4\&{else} \&{begin} \37$\\{str\_room}(\|l)$;\6
\&{for} $\|k\K\|j\mathrel{\&{to}}\|j+\|l-1$ \1\&{do}\5
$\\{append\_char}(\\{buffer}[\|k])$;\2\6
$\\{text}(\|p)\K\\{make\_string}$;\6
\&{end};\2\6
\&{stat} \37$\\{incr}(\\{st\_count})$;\ \&{tats}\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~194.\fi

\M196. The value of \\{hash\_prime} should be roughly 85\% of \\{hash\_size},
and it
should be a prime number.  The theory of hashing tells us to expect fewer
than two table probes, on the average, when the search is successful.

\Y\P$\4\X196:Compute the hash code \|h\X\S$\6
$\|h\K\\{buffer}[\|j]$;\6
\&{for} $\|k\K\|j+1\mathrel{\&{to}}\|j+\|l-1$ \1\&{do}\6
\&{begin} \37$\|h\K\|h+\|h+\\{buffer}[\|k]$;\6
\&{while} $\|h\G\\{hash\_prime}$ \1\&{do}\5
$\|h\K\|h-\\{hash\_prime}$;\2\6
\&{end}\2\par
\U section~194.\fi

\M197. \P$\X197:Search \\{eqtb} for equivalents equal to \|p\X\S$\6
\&{for} $\|q\K1\mathrel{\&{to}}\\{hash\_size}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{equiv}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"EQUIV("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end}\2\par
\U section~179.\fi

\M198. We need to put \MF's ``primitive'' symbolic tokens into the hash
table, together with their command code (which will be the \\{eq\_type})
and an operand (which will be the \\{equiv}). The \\{primitive} procedure
does this, in a way that no \MF\ user can. The global value \\{cur\_sym}
contains the new \\{eqtb} pointer after \\{primitive} has acted.

\Y\P\&{init} \37\&{procedure}\1\  \37$\\{primitive}(\|s:\\{str\_number};\,\35%
\|c:\\{halfword};\,\35\|o:\\{halfword})$;\6
\4\&{var} \37\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\6
\|j: \37\\{small\_number};\C{index into \\{buffer}}\6
\|l: \37\\{small\_number};\C{length of the string}\2\6
\&{begin} \37$\|k\K\\{str\_start}[\|s]$;\5
$\|l\K\\{str\_start}[\|s+1]-\|k$;\C{we will move \|s into the (empty) %
\\{buffer}}\6
\&{for} $\|j\K0\mathrel{\&{to}}\|l-1$ \1\&{do}\5
$\\{buffer}[\|j]\K\\{str\_pool}[\|k+\|j]$;\2\6
$\\{cur\_sym}\K\\{id\_lookup}(0,\39\|l)$;\6
\\{flush\_string};\5
$\\{text}(\\{cur\_sym})\K\|s$;\C{we don't want to have the string twice}\6
$\\{eq\_type}(\\{cur\_sym})\K\|c$;\5
$\\{equiv}(\\{cur\_sym})\K\|o$;\6
\&{end};\6
\&{tini}\par
\fi

\M199. Many of \MF's primitives need no \\{equiv}, since they are identifiable
by their \\{eq\_type} alone. These primitives are loaded into the hash table
as follows:

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"\&"},\39\\{ampersand},\390)$;\6
$\\{primitive}(\.{".."},\39\\{path\_join},\390)$;\6
$\\{primitive}(\.{"="},\39\\{equals},\390)$;\6
$\\{primitive}(\.{"["},\39\\{left\_bracket},\390)$;\6
$\\{primitive}(\.{"/"},\39\\{slash},\390)$;\6
$\\{primitive}(\.{"]"},\39\\{right\_bracket},\390)$;\6
$\\{primitive}(\.{"\}"},\39\\{right\_brace},\390)$;\6
$\\{primitive}(\.{"\{"},\39\\{left\_brace},\390)$;\6
$\\{primitive}(\.{":"},\39\\{colon},\390)$;\6
$\\{primitive}(\.{":="},\39\\{assignment},\390)$;\6
$\\{primitive}(\.{","},\39\\{comma},\390)$;\6
$\\{primitive}(\.{";"},\39\\{semicolon},\390)$;\7
$\\{primitive}(\.{"addto"},\39\\{drawing\_command},\390)$;\6
$\\{primitive}(\.{"and"},\39\\{and\_command},\390)$;\6
$\\{primitive}(\.{"as"},\39\\{as\_token},\390)$;\6
$\\{primitive}(\.{"at"},\39\\{at\_token},\390)$;\6
$\\{primitive}(\.{"begingroup"},\39\\{begin\_group},\390)$;\6
$\\{primitive}(\.{"controls"},\39\\{controls},\390)$;\6
$\\{primitive}(\.{"curl"},\39\\{curl\_command},\390)$;\6
$\\{primitive}(\.{"cycle"},\39\\{cycle},\390)$;\6
$\\{primitive}(\.{"delimiters"},\39\\{delimiters},\390)$;\6
$\\{primitive}(\.{"endgroup"},\39\\{end\_group},\390)$;\6
$\\{primitive}(\.{"everyjob"},\39\\{every\_job\_command},\390)$;\6
$\\{primitive}(\.{"from"},\39\\{from\_token},\390)$;\6
$\\{primitive}(\.{"if"},\39\\{if\_test},\390)$;\6
$\\{primitive}(\.{"interim"},\39\\{interim\_command},\390)$;\6
$\\{primitive}(\.{"let"},\39\\{let\_command},\390)$;\6
$\\{primitive}(\.{"of"},\39\\{of\_token},\390)$;\6
$\\{primitive}(\.{"openwindow"},\39\\{open\_window},\390)$;\6
$\\{primitive}(\.{"randomseed"},\39\\{random\_seed},\390)$;\6
$\\{primitive}(\.{"relax"},\39\\{relax},\390)$;\6
$\\{primitive}(\.{"reportstats"},\39\\{report\_stats},\390)$;\6
$\\{primitive}(\.{"save"},\39\\{save\_command},\390)$;\6
$\\{primitive}(\.{"shipout"},\39\\{ship\_out\_command},\390)$;\6
$\\{primitive}(\.{"tension"},\39\\{tension},\390)$;\6
$\\{primitive}(\.{"to"},\39\\{to\_token},\390)$;\6
$\\{primitive}(\.{"until"},\39\\{until\_token},\390)$;\par
\fi

\M200. Each primitive has a corresponding inverse, so that it is possible to
display the cryptic numeric contents of \\{eqtb} in symbolic form.
Every call of \\{primitive} in this program is therefore accompanied by some
straightforward code that forms part of the \\{print\_cmd\_mod} routine
explained below.

\Y\P$\4\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of primitives\X%
\S$\6
\4\\{ampersand}: \37$\\{print}(\.{"\&"})$;\6
\4\\{and\_command}: \37$\\{print}(\.{"and"})$;\6
\4\\{as\_token}: \37$\\{print}(\.{"as"})$;\6
\4\\{assignment}: \37$\\{print}(\.{":="})$;\6
\4\\{at\_token}: \37$\\{print}(\.{"at"})$;\6
\4\\{begin\_group}: \37$\\{print}(\.{"begingroup"})$;\6
\4\\{colon}: \37$\\{print}(\.{":"})$;\6
\4\\{comma}: \37$\\{print}(\.{","})$;\6
\4\\{controls}: \37$\\{print}(\.{"controls"})$;\6
\4\\{curl\_command}: \37$\\{print}(\.{"curl"})$;\6
\4\\{cycle}: \37$\\{print}(\.{"cycle"})$;\6
\4\\{delimiters}: \37$\\{print}(\.{"delimiters"})$;\6
\4\\{drawing\_command}: \37$\\{print}(\.{"addto"})$;\6
\4\\{end\_group}: \37$\\{print}(\.{"endgroup"})$;\6
\4\\{equals}: \37$\\{print}(\.{"="})$;\6
\4\\{every\_job\_command}: \37$\\{print}(\.{"everyjob"})$;\6
\4\\{from\_token}: \37$\\{print}(\.{"from"})$;\6
\4\\{if\_test}: \37$\\{print}(\.{"if"})$;\6
\4\\{interim\_command}: \37$\\{print}(\.{"interim"})$;\6
\4\\{left\_brace}: \37$\\{print}(\.{"\{"})$;\6
\4\\{left\_bracket}: \37$\\{print}(\.{"["})$;\6
\4\\{let\_command}: \37$\\{print}(\.{"let"})$;\6
\4\\{of\_token}: \37$\\{print}(\.{"of"})$;\6
\4\\{open\_window}: \37$\\{print}(\.{"openwindow"})$;\6
\4\\{path\_join}: \37$\\{print}(\.{".."})$;\6
\4\\{random\_seed}: \37$\\{print}(\.{"randomseed"})$;\6
\4\\{relax}: \37$\\{print}(\.{"relax"})$;\6
\4\\{report\_stats}: \37$\\{print}(\.{"reportstats"})$;\6
\4\\{right\_brace}: \37$\\{print}(\.{"\}"})$;\6
\4\\{right\_bracket}: \37$\\{print}(\.{"]"})$;\6
\4\\{save\_command}: \37$\\{print}(\.{"save"})$;\6
\4\\{semicolon}: \37$\\{print}(\.{";"})$;\6
\4\\{ship\_out\_command}: \37$\\{print}(\.{"shipout"})$;\6
\4\\{slash}: \37$\\{print}(\.{"/"})$;\6
\4\\{tension}: \37$\\{print}(\.{"tension"})$;\6
\4\\{to\_token}: \37$\\{print}(\.{"to"})$;\6
\4\\{until\_token}: \37$\\{print}(\.{"until"})$;\par
\A sections~214, 549, 554, 562, 572, 589, 672, 740, 752, and~784.
\U section~495.\fi

\M201. We will deal with the other primitives later, at some point in the
program
where their \\{eq\_type} and \\{equiv} values are more meaningful.  For
example,
the primitives for macro definitions will be loaded when we consider the
routines that define macros.
It is easy to find where each particular
primitive was treated by looking in the index at the end; for example, the
section where \.{"def"} entered \\{eqtb} is listed under `\&{def} primitive'.
\fi

\N202.  \[xx] Token lists.
A \MF\ token is either symbolic or numeric or a string, or it denotes
a macro parameter; so there are four corresponding ways to encode it
internally: (1)~A symbolic token whose hash code is~\|p
is represented by the number \|p, in the \\{info} field of a single-word
node in~\\{mem}. (2)~A numeric token whose \\{scaled} value is~\|v is
represented in a two-word node of~\\{mem}; the \\{info} field is \\{numeric%
\_token},
and the \\{value} field holds~\|v.
The fact that this token appears in a two-word node rather than a
one-word node is, of course, clear from the node address.
(3)~A string token is also represented in a two-word node; the \\{info}
field is \\{string\_token}, and the
\\{value} field holds the corresponding \\{str\_number}. (4)~Macro parameters
are like symbolic tokens in that they appear in \\{info} fields of
one-word nodes. The $k$th parameter of type \&{expr} is called
$\\{expr\_base}+\|k$; the $k$th of type \&{suffix} is called $\\{suffix\_base}+%
\|k$;
the $k$th of type \&{text} is called $\\{text\_base}+\|k$. (Here $0\L\|k<%
\\{param\_size}$.)
Actual values of these parameters are kept in a separate stack, as we will
see later.  The constants \\{expr\_base}, \\{suffix\_base}, and \\{text\_base}
are,
of course, chosen so that there will be no confusion between symbolic
tokens and parameters of various types.

\Y\P\D \37$\\{token\_node\_size}=2$\C{the number of words in a large token
node}\par
\P\D \37$\\{value}(\#)\S\\{mem}[\#+1].\\{int}$\C{the value stored in a large
token node}\par
\P\D \37$\\{expr\_base}\S\\{hash\_size}+1$\C{code for the zeroth \&{expr}
parameter}\par
\P\D \37$\\{suffix\_base}\S\\{expr\_base}+\\{param\_size}$\C{code for the
zeroth \&{suffix} parameter}\par
\P\D \37$\\{text\_base}\S\\{suffix\_base}+\\{param\_size}$\C{code for the
zeroth \&{text} parameter}\par
\Y\P$\4\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $\\{text\_base}+\\{param\_size}>\\{max\_halfword}$ \1\&{then}\5
$\\{bad}\K21$;\2\par
\fi

\M203. A numeric token is created by the following trivial routine.

\Y\P\4\&{function}\1\  \37$\\{new\_num\_tok}(\|v:\\{scaled})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|p)\K\|v$;\5
$\\{info}(\|p)\K\\{numeric\_token}$;\5
$\\{new\_num\_tok}\K\|p$;\6
\&{end};\par
\fi

\M204. A token list is a singly linked list of nodes in \\{mem}, where
each node contains a token and a link.  Here's a subroutine that gets rid
of a token list when it is no longer needed.

\Y\P\4\&{procedure}\1\  \37$\\{flush\_token\_list}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the node being recycled}\2\6
\&{begin} \37\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{link}(\|p)$;\6
\&{if} $\|q<\\{hi\_mem\_base}$ \1\&{then}\5
$\\{free\_node}(\|q,\39\\{token\_node\_size})$\ \&{else} $\\{free\_avail}(%
\|q)$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M205. The procedure \\{show\_token\_list}, which prints a symbolic form of
the token list that starts at a given node \|p, illustrates these
conventions. The token list being displayed should not begin with a reference
count. However, the procedure is intended to be robust, so that if the
memory links are awry or if \|p is not really a pointer to a token list,
nothing catastrophic will happen.

An additional parameter \|q is also given; this parameter is either zero
or it points to a node in the token list where a certain magic computation
takes place that will be explained later. (Basically, \|q is nonzero when
we are printing the two-line context information at the time of an error
message; \|q marks the place corresponding to where the second line
should begin.)

The generation will stop, and `\.{ETC.}' will be printed, if the length
of printing exceeds a given limit~\|l. Unusual entries are printed in the
form of all-caps symbolic tokens preceded by a percent sign, e.g.,
`\.{\%BAD}'.

\Y\P$\4\X205:Declare the procedure called \\{show\_token\_list}\X\S$\6
\4\&{procedure}\1\  \37$\\{show\_token\_list}(\|p,\39\|q:\\{integer};\,\35\|l:%
\\{integer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\\{class},\39\|c$: \37\\{small\_number};\C{the \\{char\_class} of
previous and new tokens}\6
$\|r,\39\|v$: \37\\{integer};\C{temporary registers}\2\6
\&{begin} \37$\\{class}\K\\{percent\_class}$;\5
$\\{tally}\K0$;\6
\&{while} $(\|p\I\\{null})\W(\\{tally}<\|l)$ \1\&{do}\6
\&{begin} \37\&{if} $\|p=\|q$ \1\&{then}\5
\X515:Do magic computation\X;\2\6
\X206:Display token \|p and set \|c to its class; but \&{return} if there are
problems\X;\6
$\\{class}\K\|c$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{print}(\.{"ETC."})$;\2\6
\4\\{exit}: \37\&{end};\par
\U section~155.\fi

\M206. \P$\X206:Display token \|p and set \|c to its class; but \&{return} if
there are problems\X\S$\6
$\|c\K\\{letter\_class}$;\C{the default}\6
\&{if} $(\|p<\\{first\_mem})\V(\|p>\\{mem\_end})$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\%CLOBBERED"})$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\|p<\\{hi\_mem\_base}$ \1\&{then}\5
\X207:Display numeric or string token\X\6
\4\&{else} \&{begin} \37$\|r\K\\{info}(\|p)$;\6
\&{if} $\|r\G\\{expr\_base}$ \1\&{then}\5
\X210:Display a parameter token\X\6
\4\&{else} \&{if} $\|r<1$ \1\&{then}\6
\&{if} $\|r=0$ \1\&{then}\5
\X209:Display a generic subscript\X\6
\4\&{else} $\\{print}(\.{"\%IMPOSSIBLE"})$\2\6
\4\&{else} \&{begin} \37$\|r\K\\{text}(\|r)$;\6
\&{if} $(\|r<\.{"\ "})\V(\|r\G\\{str\_ptr})$ \1\&{then}\5
$\\{print}(\.{"\%NONEXISTENT"})$\6
\4\&{else} \X211:Print the \|rth string as a symbolic token and set \|c to its
class\X;\2\6
\&{end};\2\2\6
\&{end}\2\par
\U section~205.\fi

\M207. \P$\X207:Display numeric or string token\X\S$\6
\&{if} $\\{info}(\|p)=\\{numeric\_token}$ \1\&{then}\5
\X208:Display a numeric token\X\6
\4\&{else} \&{if} $\\{info}(\|p)=\\{string\_token}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{""}\.{""})$;\5
$\\{print}(\\{value}(\|p))$;\5
$\\{print\_char}(\.{""}\.{""})$;\5
$\|c\K\\{string\_class}$;\6
\&{end}\6
\4\&{else} $\\{print}(\.{"\%BAD"})$\2\2\par
\U section~206.\fi

\M208. \P$\X208:Display a numeric token\X\S$\6
\&{begin} \37\&{if} $\\{class}=\\{digit\_class}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
$\|v\K\\{value}(\|p)$;\6
\&{if} $\|v<0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{class}=\\{left\_bracket\_class}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
$\\{print\_char}(\.{"["})$;\5
$\\{print\_scaled}(\|v)$;\5
$\\{print\_char}(\.{"]"})$;\5
$\|c\K\\{right\_bracket\_class}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_scaled}(\|v)$;\5
$\|c\K\\{digit\_class}$;\6
\&{end};\2\6
\&{end}\par
\U section~207.\fi

\M209. Strictly speaking, a genuine token will never have $\\{info}(\|p)=0$.
But we will see later (in the \\{print\_variable\_name} routine) that
it is convenient to let $\\{info}(\|p)=0$ stand for `\.{[]}'.

\Y\P$\4\X209:Display a generic subscript\X\S$\6
\&{begin} \37\&{if} $\\{class}=\\{left\_bracket\_class}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
$\\{print}(\.{"[]"})$;\5
$\|c\K\\{right\_bracket\_class}$;\6
\&{end}\par
\U section~206.\fi

\M210. \P$\X210:Display a parameter token\X\S$\6
\&{begin} \37\&{if} $\|r<\\{suffix\_base}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\%EXPR"})$;\5
$\|r\K\|r-(\\{expr\_base})$;\6
\&{end}\6
\4\&{else} \&{if} $\|r<\\{text\_base}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\%SUFFIX"})$;\5
$\|r\K\|r-(\\{suffix\_base})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print}(\.{"\%TEXT"})$;\5
$\|r\K\|r-(\\{text\_base})$;\6
\&{end};\2\2\6
$\\{print\_int}(\|r)$;\5
$\|c\K\\{digit\_class}$;\6
\&{end}\par
\U section~206.\fi

\M211. \P$\X211:Print the \|rth string as a symbolic token and set \|c to its
class\X\S$\6
\&{begin} \37$\|c\K\\{char\_class}[\\{str\_pool}[\\{str\_start}[\|r]]]$;\6
\&{if} $\|c=\\{class}$ \1\&{then}\6
\&{case} $\|c$ \1\&{of}\6
\4\\{letter\_class}: \37$\\{print\_char}(\.{"."})$;\6
\4\\{isolated\_classes}: \37\\{do\_nothing};\6
\4\&{othercases} \37$\\{print\_char}(\.{"\ "})$\2\6
\&{endcases};\2\6
$\\{print}(\|r)$;\6
\&{end}\par
\U section~206.\fi

\M212. Macro definitions are kept in \MF's memory in the form of token lists
that have a few extra one-word nodes at the beginning.

The first node contains a reference count that is used to tell when the
list is no longer needed. To emphasize the fact that a reference count is
present, we shall refer to the \\{info} field of this special node as the
\\{ref\_count} field.

The next node or nodes after the reference count serve to describe the
formal parameters. They either contain a code word that specifies all
of the parameters, or they contain zero or more parameter tokens followed
by the code `\\{general\_macro}'.

\Y\P\D \37$\\{ref\_count}\S\\{info}$\C{reference count preceding a macro
definition or pen header}\par
\P\D \37$\\{add\_ref}(\#)\S\\{incr}(\\{ref\_count}(\#))$\C{make a new reference
to a macro list}\par
\P\D \37$\\{general\_macro}=0$\C{preface to a macro defined with a parameter
list}\par
\P\D \37$\\{primary\_macro}=1$\C{preface to a macro with a \&{primary}
parameter}\par
\P\D \37$\\{secondary\_macro}=2$\C{preface to a macro with a \&{secondary}
parameter}\par
\P\D \37$\\{tertiary\_macro}=3$\C{preface to a macro with a \&{tertiary}
parameter}\par
\P\D \37$\\{expr\_macro}=4$\C{preface to a macro with an undelimited \&{expr}
parameter}\par
\P\D \37$\\{of\_macro}=5$\C{preface to a macro with `\&{expr} \|x \&{of}~\|y'
parameters}\par
\Y\P\4\&{procedure}\1\  \37$\\{delete\_ref}(\|p:\\{pointer})$;\C{\|p points to
the reference count of a macro list that is 		losing one reference}\2\6
\&{begin} \37\&{if} $\\{ref\_count}(\|p)=\\{null}$ \1\&{then}\5
$\\{flush\_token\_list}(\|p)$\6
\4\&{else} $\\{decr}(\\{ref\_count}(\|p))$;\2\6
\&{end};\par
\fi

\M213. \P$\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"primary"},\39\\{param\_level},\39\\{primary\_macro})$;\6
$\\{primitive}(\.{"secondary"},\39\\{param\_level},\39\\{secondary\_macro})$;\6
$\\{primitive}(\.{"tertiary"},\39\\{param\_level},\39\\{tertiary\_macro})$;\par
\fi

\M214. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{param\_level}: \37\&{if} $\mathbin{\&{mod}}=\\{primary\_macro}$ \1\&{then}%
\5
$\\{print}(\.{"primary"})$\6
\4\&{else} \&{if} $\mathbin{\&{mod}}=\\{secondary\_macro}$ \1\&{then}\5
$\\{print}(\.{"secondary"})$\6
\4\&{else} $\\{print}(\.{"tertiary"})$;\2\2\par
\fi

\M215. The following subroutine displays a macro, given a pointer to its
reference count.

\Y\P\X495:Declare the procedure called \\{print\_cmd\_mod}\X\6
\4\&{procedure}\1\  \37$\\{show\_macro}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{temporary storage}\2\6
\&{begin} \37$\|p\K\\{link}(\|p)$;\C{bypass the reference count}\6
\&{while} $\\{info}(\|p)>\\{of\_macro}$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\.{"("})$;\5
$\|q\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\\{show\_token\_list}(\|p,\39\\{null},\391)$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{print\_char}(\.{")"})$;\5
$\|p\K\|q$;\6
\&{end};\2\6
\&{case} $\\{info}(\|p)$ \1\&{of}\6
\4\\{general\_macro}: \37$\\{print}(\.{"->"})$;\6
\4$\\{primary\_macro},\39\\{secondary\_macro},\39\\{tertiary\_macro}$: \37%
\&{begin} \37$\\{print\_char}(\.{"<"})$;\5
$\\{print\_cmd\_mod}(\\{param\_level},\39\\{info}(\|p))$;\5
$\\{print}(\.{">->"})$;\6
\&{end};\6
\4\\{expr\_macro}: \37$\\{print}(\.{"<expression>->"})$;\6
\4\\{of\_macro}: \37$\\{print}(\.{"<expression>of<primary>->"})$;\2\6
\&{end};\C{there are no other cases}\6
$\\{show\_token\_list}(\\{link}(\|p),\39\\{null},\391000)$;\6
\&{end};\par
\fi

\N216.  \[xx] Data structures for variables.
The variables of \MF\ programs can be simple, like `\.x', or they can
combine the structural properites of arrays and records, like `\.{x20a.b}'.
A \MF\ user assigns a type to a variable like \.{x20a.b} by saying, for
example, `\.{boolean} \.{x20a.b}'. It's time for us to study how such
things are represented inside of the computer.

Each variable value occupies two consecutive words, either in a
two-word node called a value node, or as a two-word subfield of a larger node.
One of those two words is called the \\{value} field; it is an integer,
containing either a \\{scaled} numeric value or a pointer to some structured
value. (It might also be subdivided into halfwords, in which case
it is referred to be another name instead of \\{value}.) The other
word is broken into subfields called \\{type}, \\{name\_type}, and \\{link}.
The \\{type} field is a quarterword that specifies the variable's type,
and \\{name\_type} is a quarterword from which \MF\ can reconstruct
the variable's name (sometimes by using the \\{link} field as well).
Thus, only 1.25 words are actually devoted to values; the other three-quarters
of a word are overhead, but they aren't wasted because they permit sparse
arrays
and meaningful diagnostics.

In this section we shall be concerned only with the structural aspects of
variables, not their values. Later parts of the program will change the
\\{type} and \\{value} fields, but we shall treat those fields as black boxes
whose contents should not be touched.

However, if the \\{type} field is \\{structured}, there is no \\{value} field,
and the second word is broken into two pointer fields called \\{attr\_head}
and \\{subscr\_head}. Those fields point to additional nodes that
contain structural information.

\Y\P\D \37$\\{type}(\#)\S\\{mem}[\#].\\{hh}.\\{b0}$\C{identifies what kind of
node this is}\par
\P\D \37$\\{name\_type}(\#)\S\\{mem}[\#].\\{hh}.\\{b1}$\C{a clue to the name of
this variable}\par
\P\D \37$\\{subscr\_head\_loc}(\#)\S\#+1$\C{where \\{value}, \\{subscr\_head}
and \\{attr\_head} are}\par
\P\D \37$\\{attr\_head}(\#)\S\\{info}(\\{subscr\_head\_loc}(\#))$\C{pointer to
attribute info}\par
\P\D \37$\\{subscr\_head}\S\\{link}(\\{subscr\_head\_loc}(\#))$\C{pointer to
subscript info}\par
\P\D \37$\\{value\_node\_size}=2$\C{the number of words in a value node}\par
\fi

\M217. An attribute node is three words long. Two of these words contain %
\\{type}
and \\{value} fields as described above, and the third word contains
additional information:  there is an \\{attr\_loc} field, which contains the
hash address of the token that names this attribute; and a \\{parent} field,
which points to the structured type at the next higher level (i.e., at the
level to which this attribute is subsidiary).  The \\{name\_type} in an
attribute node is `\\{attr}'.  The \\{link} field points to the
next attribute with the same parent; these are arranged in increasing
order, so that $\\{attr\_loc}(\\{link}(\|p))>\\{attr\_loc}(\|p)$. The final
attribute
node links to the constant \\{end\_attr}, whose \\{attr\_loc} field is
greater than any legal hash address. The \\{attr\_head} in the parent
points to a value node whose \\{name\_type} is \\{structured\_root}; this
node represents the null attribute, i.e., the variable that occurs
when no attributes are attached to the parent. The \\{link} field in
this special node points to an attribute node whose \\{attr\_loc} field
is zero; this node represents a generic subscript `\.{[]}' attached
to the parent, and its \\{link} field points to the first non-special
attribute node (or to \\{end\_attr} if there are none).

A subscript node likewise occupies three words, with \\{type} and \\{value}
fields
plus extra information; its \\{name\_type} is \\{subscr}. In this case the
third word is called the \\{subscript} field, which is a \\{scaled} integer.
The \\{link} field points to the subscript node with the next larger
subscript, if any; otherwise the \\{link} points to the attribute node
for generic subscripts at this level. We have seen that the latter node
contains an upward pointer, so that the parent can be deduced.

The \\{name\_type} in a parent-less value node is \\{root}, and the \\{link}
is the hash address of the token that names this value.

In other words, variables have a heirarchical structure that includes
enough threads running around so that the program is able to move easily
between siblings, parents, and children. An example should be helpful:
(The reader is advised to draw a picture while reading the following
description, since that will help to firm up the ideas.)
Suppose that `\.x' and `\.{x.a}' and `\.{x[]b}' and `\.{x5}'
and `\.{x20b}' have been mentioned in a user's program, where
\.{x[]b} has been declared to be of \&{boolean} type. Let $\|h(\|x)$, $\|h(%
\|a)$,
and $\|h(\|b)$ be the hash addresses of \.x, \.a, and \.b. Then
$\\{eq\_type}(\|h(\|x))=\\{name}$ and $\\{equiv}(\|h(\|x))=\|p$, where \|p~is a
two-word value
node with $\\{name\_type}(\|p)=\\{root}$ and $\\{link}(\|p)=\|h(\|x)$. We have
$\\{type}(\|p)=\\{structured}$,
$\\{attr\_head}(\|p)=\|q$, and $\\{subscr\_head}(\|p)=\|r$, where \|q points to
a value
node and \|r to a subscript node. (Are you still following this? Use
a pencil to draw a diagram.) The lone variable `\.x' is represented by
$\\{type}(\|q)$ and $\\{value}(\|q)$; furthermore
$\\{name\_type}(\|q)=\\{structured\_root}$ and $\\{link}(\|q)=\\{q1}$, where %
\\{q1} points
to an attribute node representing `\.{x[]}'. Thus $\\{name\_type}(\\{q1})=%
\\{attr}$,
$\\{attr\_loc}(\\{q1})=\\{generic\_subscript}=0$, $\\{parent}(\\{q1})=\|p$,
$\\{type}(\\{q1})=\\{structured}$, $\\{attr\_head}(\\{q1})=\\{qq}$, and $%
\\{subscr\_head}(\\{q1})=\\{qq1}$;
\\{qq} is a value node with $\\{type}(\\{qq})=\\{numeric\_type}$ (assuming that
\.{x5} is
numeric, because \\{qq} represents `\.{x[]}' with no further attributes),
$\\{name\_type}(\\{qq})=\\{structured\_head}$, and
$\\{link}(\\{qq})=\\{qq1}$. (Now pay attention to the next part.) Node \\{qq1}
is
an attribute node representing `\.{x[][]}', which has never yet
occurred; its \\{type} field is \\{undefined}, and its \\{value} field is
undefined. We have $\\{name\_type}(\\{qq1})=\\{attr}$, $\\{attr\_loc}(\\{qq1})=%
\\{generic\_subscript}$,
$\\{parent}(\\{qq1})=\\{q1}$, and $\\{link}(\\{qq1})=\\{qq2}$. Well, \\{qq2}
represents
`\.{x[]b}', so $\\{type}(\\{qq2})=\\{unknown\_boolean}$; also $\\{attr\_loc}(%
\\{qq2})=\|h(\|b)$,
$\\{parent}(\\{qq2})=\\{q1}$, $\\{name\_type}(\\{qq2})=\\{attr}$, $\\{link}(%
\\{qq2})=\\{end\_attr}$.
(Maybe colored lines will help untangle your picture.)
Node \|r is a subscript node with \\{type} and \\{value}
representing `\.{x5}'; $\\{name\_type}(\|r)=\\{subscr}$, $\\{subscript}(%
\|r)=5.0$,
and $\\{link}(\|r)=\\{r1}$ is another subscript node. To complete the picture,
see if you can guess what $\\{link}(\\{r1})$ is; give up? It's~\\{q1}.
Furthermore $\\{subscript}(\\{r1})=20.0$, $\\{name\_type}(\\{r1})=\\{subscr}$,
$\\{type}(\\{r1})=\\{structured}$, $\\{attr\_head}(\\{r1})=\\{qqq}$, $\\{subscr%
\_head}(\\{r1})=\\{qqq1}$,
and we finish things off with three more nodes
\\{qqq}, \\{qqq1}, and \\{qqq2} hung onto~\\{r1}. (Perhaps you should start
again
with a larger sheet of paper.) The value of variable \.{x20b}
appears in node~\\{qqq2}, as you can well imagine.

If the example in the previous paragraph doesn't make things clear, a glance
at some of the simpler subroutines below will reveal how things work out
in practice.

The only really unusual thing about these conventions is the use of
generic subscript attributes. The idea is to avoid repeating a lot of
type information when many elements of an array are identical macros
(for which distinct values need not be stored) or when they don't have
all of the possible attributes. Branches of the structure below generic
subscript attributes do not carry actual values except for macro identifiers;
branches of the structure below subscript nodes do not carry significant
information in their generic subscript attributes.

\Y\P\D \37$\\{attr\_loc\_loc}(\#)\S\#+2$\C{where the \\{attr\_loc} and %
\\{parent} fields are}\par
\P\D \37$\\{attr\_loc}(\#)\S\\{info}(\\{attr\_loc\_loc}(\#))$\C{hash address of
this attribute}\par
\P\D \37$\\{parent}(\#)\S\\{link}(\\{attr\_loc\_loc}(\#))$\C{pointer to %
\\{structured} variable}\par
\P\D \37$\\{subscript}(\#)\S\\{mem}[\#+2].\\{sc}$\C{subscript of this variable}%
\par
\P\D \37$\\{attr\_node\_size}=3$\C{the number of words in an attribute node}\par
\P\D \37$\\{subscr\_node\_size}=3$\C{the number of words in a subscript node}%
\par
\P\D \37$\\{generic\_subscript}=0$\C{code for the attribute `\.{[]}'}\par
\Y\P$\4\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}\S$\6
$\\{attr\_loc}(\\{end\_attr})\K\\{hash\_size}+1$;\5
$\\{parent}(\\{end\_attr})\K\\{null}$;\par
\fi

\M218. Variables of type \&{pair} will have values that point to four-word
nodes containing two numeric values. The first of these values has
$\\{name\_type}=\\{x\_part\_sector}$ and the second has $\\{name\_type}=\\{y%
\_part\_sector}$;
the \\{link} in the first points back to the node whose \\{value} points
to this four-word node.

Variables of type \&{transform} are similar, but in this case their
\\{value} points to a 12-word node containing six values, identified by
\\{x\_part\_sector}, \\{y\_part\_sector}, \\{xx\_part\_sector}, \\{xy\_part%
\_sector},
\\{yx\_part\_sector}, and \\{yy\_part\_sector}.

When an entire structured variable is saved, the \\{root} indication
is temporarily replaced by \\{saved\_root}.

Some variables have no name; they just are used for temporary storage
while expressions are being evaluated. We call them {\sl capsules}.

Thus, we have a variety of different codes that can be present in
the \\{name\_type} field of a variable. All such codes are defined here:

\Y\P\D \37$\\{root}=0$\C{\\{name\_type} at the top level of a variable}\par
\P\D \37$\\{saved\_root}=1$\C{same, when the variable has been saved}\par
\P\D \37$\\{structured\_root}=2$\C{\\{name\_type} where a \\{structured} branch
occurs}\par
\P\D \37$\\{subscr}=3$\C{\\{name\_type} in a subscript node}\par
\P\D \37$\\{attr}=4$\C{\\{name\_type} in an attribute node}\par
\P\D \37$\\{x\_part\_sector}=5$\C{\\{name\_type} in the \&{xpart} of a node}\par
\P\D \37$\\{y\_part\_sector}=6$\C{\\{name\_type} in the \&{ypart} of a node}\par
\P\D \37$\\{xx\_part\_sector}=7$\C{\\{name\_type} in the \&{xxpart} of a node}%
\par
\P\D \37$\\{xy\_part\_sector}=8$\C{\\{name\_type} in the \&{xypart} of a node}%
\par
\P\D \37$\\{yx\_part\_sector}=9$\C{\\{name\_type} in the \&{yxpart} of a node}%
\par
\P\D \37$\\{yy\_part\_sector}=10$\C{\\{name\_type} in the \&{yypart} of a node}%
\par
\P\D \37$\\{capsule}=11$\C{\\{name\_type} in stashed-away subexpressions}\Y\par
\P\D \37$\\{x\_part\_loc}(\#)\S\#$\C{where the \&{xpart} is found in a pair or
transform node}\par
\P\D \37$\\{y\_part\_loc}(\#)\S\#+2$\C{where the \&{ypart} is found in a pair
or transform node}\par
\P\D \37$\\{xx\_part\_loc}(\#)\S\#+4$\C{where the \&{xxpart} is found in a
transform node}\par
\P\D \37$\\{sy\_part\_loc}(\#)\S\#+6$\C{where the \&{xypart} is found in a
transform node}\par
\P\D \37$\\{yx\_part\_loc}(\#)\S\#+8$\C{where the \&{yxpart} is found in a
transform node}\par
\P\D \37$\\{yy\_part\_loc}(\#)\S\#+10$\C{where the \&{yypart} is found in a
transform node}\par
\fi

\M219. Tokens are of type \\{name\_token} when they first appear, but they
point
to \\{null} until they are first used as the root of a variable.
The following subroutine establishes the root node on such grand occasions.

\Y\P\4\&{procedure}\1\  \37$\\{new\_root}(\|x:\\{pointer})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{type}(\|p)\K\\{undefined}$;\5
$\\{name\_type}(\|p)\K\\{root}$;\5
$\\{link}(\|p)\K\|x$;\5
$\\{equiv}(\|x)\K\|p$;\6
\&{end};\par
\fi

\M220. If $\\{type}(\|p)=\\{pair\_type}$ and $\\{value}(\|p)=\\{null}$, the
procedure call
$\\{init\_big\_node}(\|p,\\{pair\_node\_size})$ will allocate a pair node for~%
\|p.
And $\\{init\_big\_node}(\|p,\\{transform\_node\_size})$ will do a similar
trick
when $\\{type}(\|p)=\\{transform\_type}$.

\Y\P\D \37$\\{pair\_node\_size}=4$\C{the number of words in a pair node}\par
\P\D \37$\\{transform\_node\_size}=12$\C{the number of words in a transform
node}\par
\Y\P\4\&{procedure}\1\  \37$\\{init\_big\_node}(\|p:\\{pointer};\,\35\|s:%
\\{small\_number})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\|s)$;\6
\1\&{repeat} \37$\|s\K\|s-2$;\5
$\\{type}(\|q+\|s)\K\\{independent}$;\5
$\\{value}(\|q+\|s)\K0$;\5
$\\{name\_type}(\|q+\|s)\K\\{half}(\|s)+\\{x\_part\_sector}$;\5
$\\{link}(\|q+\|s)\K\\{null}$;\6
\4\&{until}\5
$\|s=0$;\2\6
$\\{link}(\|q)\K\|p$;\5
$\\{value}(\|p)\K\|q$;\6
\&{end};\par
\fi

\M221. These conventions for variable representation are illustrated by the
\\{print\_variable\_name} routine, which displays the full name of a
variable given only a pointer to its two-word value packet.

\Y\P$\\{print\_variable\_name}(\|p:\\{pointer})$;\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{a token list that will name the variable's
suffix}\6
\|r: \37\\{pointer};\C{temporary for token list creation}\6
\&{begin} \37\&{if} $\\{name\_type}(\|p)\G\\{x\_part\_sector}$ \1\&{then}\5
\X223:Preface the output with a part specifier; \&{return} in the case of a
capsule\X;\2\6
$\|q\K\\{null}$;\6
\&{while} $\\{name\_type}(\|p)>\\{saved\_root}$ \1\&{do}\5
\X222:Ascend one level, putting a token onto list \|q and replacing \|p by its
parent\X;\2\6
$\|r\K\\{get\_avail}$;\5
$\\{info}(\|r)\K\\{link}(\|p)$;\5
$\\{link}(\|r)\K\|q$;\6
\&{if} $\\{name\_type}(\|p)=\\{saved\_root}$ \1\&{then}\5
$\\{print}(\.{"\%SAVED"})$;\2\6
$\\{show\_token\_list}(\|r,\39\\{null},\391000)$;\5
$\\{flush\_token\_list}(\|r)$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M222. \P$\X222:Ascend one level, putting a token onto list \|q and replacing %
\|p by its parent\X\S$\6
\&{begin} \37\&{if} $\\{name\_type}(\|p)=\\{subscr}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{new\_num\_tok}(\\{subscript}(\|p))$;\6
\1\&{repeat} \37$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\\{name\_type}(\|p)=\\{attr}$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{name\_type}(\|p)=\\{structured\_root}$ \1\&{then}\5
\&{goto} \37\\{found}\6
\4\&{else} \&{begin} \37\&{if} $\\{name\_type}(\|p)\I\\{attr}$ \1\&{then}\5
$\\{confusion}(\.{"var"})$;\2\6
$\|r\K\\{get\_avail}$;\5
$\\{info}(\|r)\K\\{attr\_loc}(\|p)$;\6
\&{end};\2\2\6
$\\{link}(\|r)\K\|q$;\5
$\|q\K\|r$;\6
\4\\{found}: \37$\|p\K\\{parent}(\|p)$;\6
\&{end}\par
\U section~221.\fi

\M223. \P$\X223:Preface the output with a part specifier; \&{return} in the
case of a capsule\X\S$\6
\&{begin} \37\&{case} $\\{name\_type}(\|p)$ \1\&{of}\6
\4\\{x\_part\_sector}: \37$\\{print\_char}(\.{"x"})$;\6
\4\\{y\_part\_sector}: \37$\\{print\_char}(\.{"y"})$;\6
\4\\{xx\_part\_sector}: \37$\\{print}(\.{"xx"})$;\6
\4\\{xy\_part\_sector}: \37$\\{print}(\.{"xy"})$;\6
\4\\{yx\_part\_sector}: \37$\\{print}(\.{"yx"})$;\6
\4\\{yy\_part\_sector}: \37$\\{print}(\.{"yy"})$;\6
\4\\{capsule}: \37\&{begin} \37$\\{print}(\.{"\%CAPSULE"})$;\5
$\\{print\_int}(\|p-\\{null})$;\5
\&{return};\6
\&{end};\2\6
\&{end};\C{there are no other cases}\6
$\\{print}(\.{"part\ "})$;\5
$\|p\K\\{link}(\|p-2\ast(\\{name\_type}(\|p)-\\{x\_part\_sector}))$;\6
\&{end}\par
\U section~221.\fi

\M224. Now here is a subroutine that converts an unstructured type into an
equivalent structured type, by inserting a \\{structured} node that is
capable of growing. This operation is done only when $\\{name\_type}(\|p)=%
\\{root}$,
\\{subscr}, or \\{attr}.

The procedure returns a pointer to the new node that has taken node~\|p's
place in the structure. Node~\|p itself does not move, nor are its
\\{value} or \\{type} fields changed in any way.

\Y\P\4\&{function}\1\  \37$\\{new\_structure}(\|p:\\{pointer})$: \37%
\\{pointer};\6
\4\&{var} \37$\|q,\39\|r,\39\|s$: \37\\{pointer};\C{list manipulation
registers}\2\6
\&{begin} \37\&{case} $\\{name\_type}(\|p)$ \1\&{of}\6
\4\\{root}: \37\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\|r\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{equiv}(\|q)\K\|r$;\6
\&{end};\6
\4\\{subscr}: \37\X225:Link a new subscript node \|r in place of node \|p\X;\6
\4\\{attr}: \37\X226:Link a new attribute node \|r in place of node \|p\X;\6
\4\&{othercases} \37$\\{confusion}(\.{"struct"})$\2\6
\&{endcases};\6
$\\{link}(\|r)\K\\{link}(\|p)$;\5
$\\{type}(\|r)\K\\{structured}$;\5
$\\{name\_type}(\|r)\K\\{name\_type}(\|p)$;\5
$\\{attr\_head}(\|r)\K\|p$;\5
$\\{name\_type}(\|p)\K\\{structured\_root}$;\6
$\|s\K\\{get\_node}(\\{attr\_node\_size})$;\5
$\\{link}(\|p)\K\|s$;\5
$\\{subscr\_head}(\|r)\K\|s$;\5
$\\{parent}(\|s)\K\|r$;\5
$\\{type}(\|s)\K\\{undefined}$;\5
$\\{name\_type}(\|s)\K\\{attr}$;\5
$\\{link}(\|s)\K\\{end\_attr}$;\5
$\\{attr\_loc}(\|s)\K\\{generic\_subscript}$;\5
$\\{new\_structure}\K\|r$;\6
\&{end};\par
\fi

\M225. \P$\X225:Link a new subscript node \|r in place of node \|p\X\S$\6
\&{begin} \37$\|q\K\|p$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|q)$;\6
\4\&{until}\5
$\\{name\_type}(\|q)=\\{attr}$;\2\6
$\|q\K\\{parent}(\|q)$;\5
$\|r\K\\{subscr\_head\_loc}(\|q)$;\C{$\\{link}(\|r)=\\{subscr\_head}(\|q)$}\6
\1\&{repeat} \37$\|s\K\|r$;\5
$\|r\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|r=\|p$;\2\6
$\|r\K\\{get\_node}(\\{subscr\_node\_size})$;\5
$\\{link}(\|s)\K\|r$;\5
$\\{subscript}(\|r)\K\\{subscript}(\|p)$;\6
\&{end}\par
\U section~224.\fi

\M226. \P$\X226:Link a new attribute node \|r in place of node \|p\X\S$\6
\&{begin} \37$\|q\K\\{parent}(\|p)$;\5
$\|r\K\\{attr\_head}(\|q)$;\6
\1\&{repeat} \37$\|s\K\|r$;\5
$\|r\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|r=\|p$;\2\6
$\|r\K\\{get\_node}(\\{attr\_node\_size})$;\5
$\\{link}(\|s)\K\|r$;\6
$\\{mem}[\\{attr\_loc\_loc}(\|r)]\K\\{mem}[\\{attr\_loc\_loc}(\|p)]$;\C{copy %
\\{attr\_loc} and \\{parent}}\6
\&{end}\par
\U section~224.\fi

\M227. The \\{find\_variable} routine is given a pointer~\|t to a nonempty
token
list of suffixes; it returns a pointer to the corresponding two-word
value. For example, if \|t points to token \.x followed by a numeric
token containing the value~7, \\{find\_variable} finds where the value of
\.{x7} is stored in memory. This may seem a simple task, and it
usually is, except when \.{x7} has never been referenced before.
Indeed, \.x may never have even been subscripted before; complexities
arise with respect to updating the generic subscript information.

If a macro type is detected anywhere along path~\|t, or if the first
item on \|t isn't a \\{name\_token}, the value \\{null} is returned.
Otherwise \|p will be a non-null pointer to a node such that
$\\{undefined}<\\{type}(\|p)<\\{structured}$.

\Y\P\D \37$\\{abort\_find}\S$\1\6
\&{begin} \37$\\{find\_variable}\K\\{null}$;\5
\&{return};\ \&{end}\2\par
\Y\P\4\&{function}\1\  \37$\\{find\_variable}(\|t:\\{pointer})$: \37%
\\{pointer};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{nodes in the
``value'' line}\6
$\\{pp},\39\\{qq},\39\\{rr},\39\\{ss}$: \37\\{pointer};\C{nodes in the
``generic'' line}\6
\|n: \37\\{integer};\C{subscript or attribute}\6
\\{save\_word}: \37\\{memory\_word};\C{temporary storage}\2\6
\&{begin} \37$\|p\K\\{info}(\|t)$;\5
$\|t\K\\{link}(\|t)$;\6
\&{if} $\\{eq\_type}(\|p)\I\\{name\_token}$ \1\&{then}\5
\\{abort\_find};\2\6
$\|p\K\\{equiv}(\|p)$;\5
$\\{pp}\K\|p$;\6
\&{while} $\|t\I\\{null}$ \1\&{do}\6
\&{begin} \37\X228:Make sure that both nodes \|p and \\{pp} are of %
\\{structured} type\X;\6
\&{if} $\|t<\\{hi\_mem\_base}$ \1\&{then}\5
\X229:Descend one level for the subscript $\\{value}(\|t)$\X\6
\4\&{else} \X230:Descend one level for the attribute $\\{info}(\|t)$\X;\2\6
$\|t\K\\{link}(\|t)$;\6
\&{end};\2\6
\&{if} $\\{type}(\\{pp})\G\\{structured}$ \1\&{then}\6
\&{if} $\\{type}(\\{pp})=\\{structured}$ \1\&{then}\5
$\\{pp}\K\\{attr\_head}(\\{pp})$\ \&{else} \\{abort\_find};\2\2\6
\&{if} $\\{type}(\|p)=\\{structured}$ \1\&{then}\5
$\|p\K\\{attr\_head}(\|p)$;\2\6
\&{if} $\\{type}(\|p)=\\{undefined}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{type}(\\{pp})=\\{undefined}$ \1\&{then}\5
$\\{type}(\\{pp})\K\\{numeric\_type}$;\2\6
$\\{type}(\|p)\K\\{type}(\\{pp})$;\6
\&{end};\2\6
$\\{find\_variable}\K\|p$;\6
\&{end};\par
\fi

\M228. Although \\{pp} and \|p begin together, they diverge when a subscript
occurs;
\\{pp}~stays in the generic line while \|p~goes through actual subscript
values.

\Y\P$\4\X228:Make sure that both nodes \|p and \\{pp} are of \\{structured}
type\X\S$\6
\&{if} $\\{type}(\\{pp})\I\\{structured}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{type}(\\{pp})>\\{structured}$ \1\&{then}\5
\\{abort\_find};\2\6
$\\{ss}\K\\{new\_structure}(\\{pp})$;\6
\&{if} $\|p=\\{pp}$ \1\&{then}\5
$\|p\K\\{ss}$;\2\6
$\\{pp}\K\\{ss}$;\6
\&{end};\C{now $\\{type}(\\{pp})=\\{structured}$}\2\6
\&{if} $\\{type}(\|p)\I\\{structured}$ \1\&{then}\C{it cannot be $>%
\\{structured}$}\6
$\|p\K\\{new\_structure}(\|p)$\C{now $\\{type}(\|p)=\\{structured}$}\2\par
\U section~227.\fi

\M229. We want this part of the program to be reasonably fast, in case there
are
lots of subscripts at the same level of the data structure. Therefore
we store an ``infinite'' value in the word that appears at the end of the
subscript list, even though that word isn't part of a subscript node.

\Y\P$\4\X229:Descend one level for the subscript $\\{value}(\|t)$\X\S$\6
\&{begin} \37$\|n\K\\{value}(\|t)$;\5
$\\{pp}\K\\{link}(\\{attr\_head}(\\{pp}))$;\C{now $\\{attr\_loc}(\\{pp})=%
\\{generic\_subscript}$}\6
$\|q\K\\{link}(\\{attr\_head}(\|p))$;\5
$\\{save\_word}\K\\{mem}[\\{attr\_loc\_loc}(\|q)]$;\5
$\\{subscript}(\|q)\K\\{el\_gordo}$;\5
$\|s\K\\{subscr\_head\_loc}(\|p)$;\C{$\\{link}(\|s)=\\{subscr\_head}(\|p)$}\6
\1\&{repeat} \37$\|r\K\|s$;\5
$\|s\K\\{link}(\|s)$;\6
\4\&{until}\5
$\|n\L\\{subscr}(\|s)$;\2\6
\&{if} $\|n=\\{subscr}(\|s)$ \1\&{then}\5
$\|p\K\|s$\6
\4\&{else} \&{begin} \37$\|p\K\\{get\_node}(\\{subscr\_node\_size})$;\5
$\\{link}(\|r)\K\|p$;\5
$\\{link}(\|p)\K\|s$;\5
$\\{subscript}(\|p)\K\|n$;\5
$\\{name\_type}(\|p)\K\\{subscr}$;\5
$\\{type}(\|p)\K\\{type}(\\{pp})$;\5
$\\{value}(\|p)\K\\{null}$;\6
\&{end};\2\6
$\\{mem}[\\{attr\_loc\_loc}(\|q)]\K\\{save\_word}$;\6
\&{end}\par
\U section~227.\fi

\M230. \P$\X230:Descend one level for the attribute $\\{info}(\|t)$\X\S$\6
\&{begin} \37$\|n\K\\{info}(\|t)$;\5
$\\{ss}\K\\{attr\_head}(\\{pp})$;\6
\1\&{repeat} \37$\\{rr}\K\\{ss}$;\5
$\\{ss}\K\\{link}(\\{ss})$;\6
\4\&{until}\5
$\|n\L\\{attr\_loc}(\\{ss})$;\2\6
\&{if} $\|n<\\{attr\_loc}(\\{ss})$ \1\&{then}\6
\&{begin} \37$\\{qq}\K\\{get\_node}(\\{attr\_node\_size})$;\5
$\\{link}(\\{rr})\K\\{qq}$;\5
$\\{link}(\\{qq})\K\\{ss}$;\5
$\\{attr\_loc}(\\{qq})\K\|n$;\5
$\\{name\_type}(\\{qq})\K\\{attr}$;\5
$\\{type}(\\{qq})\K\\{undefined}$;\5
$\\{parent}(\\{qq})\K\\{parent}(\\{rr})$;\5
$\\{ss}\K\\{qq}$;\6
\&{end};\2\6
\&{if} $\|p=\\{pp}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{ss}$;\5
$\\{pp}\K\\{ss}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{pp}\K\\{ss}$;\5
$\|s\K\\{attr\_head}(\|p)$;\6
\1\&{repeat} \37$\|r\K\|s$;\5
$\|s\K\\{link}(\|s)$;\6
\4\&{until}\5
$\|n\L\\{attr\_loc}(\|s)$;\2\6
\&{if} $\|n=\\{attr\_loc}(\|s)$ \1\&{then}\5
$\|p\K\|s$\6
\4\&{else} \&{begin} \37$\|p\K\\{get\_node}(\\{attr\_node\_size})$;\5
$\\{link}(\|r)\K\|p$;\5
$\\{link}(\|p)\K\|s$;\5
$\\{attr\_loc}(\|p)\K\|n$;\5
$\\{name\_type}(\|p)\K\\{attr}$;\5
$\\{type}(\|p)\K\\{type}(\\{pp})$;\5
$\\{value}(\|p)\K\\{null}$;\5
$\\{parent}(\|p)\K\\{parent}(\|r)$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~227.\fi

\M231. Variables lose their former values when they appear in a type
declaration,
or when they are defined to be macros or \&{let} equal to something else.
A subroutine will be defined later that recycles the storage associated
with any particular \\{type} or \\{value}; our goal now is to study a higher
level process called \\{flush\_variable}, which selectively frees parts of a
variable structure.

This routine has some complexity because of examples such as
$$\hbox{\tt numeric x[]a[]b}$$
which recycles all variables of the form \.{x[i]a[j]b} (and no others), while
$$\hbox{\tt def x[]a[] ...}$$
discards are variables of the form \.{x[i]a[j]} followed by an arbitrary
suffix, except for the generic \.{x[]a[]} itself. Recursion is the answer.

Parameter \|p points to the root information of the variable;
parameter \|t points to a list of one-word nodes that represent
suffixes, with $\\{info}=\\{generic\_subscript}$ for subscripts.

\Y\P\X680:Declare the procedure called \\{recycle\_value}\X\6
\X232:Declare the procedure called \\{flush\_below\_variable}\X\6
\4\&{procedure}\1\  \37$\\{flush\_variable}(\|p,\39\|t:\\{pointer};\,\35%
\\{discard\_suffixes}:\\{boolean})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|q,\39\|r$: \37\\{pointer};\C{list manipulation}\6
\|n: \37\\{halfword};\C{attribute to match}\2\6
\&{begin} \37\&{while} $\|t\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{type}(\|p)\I\\{structured}$ \1\&{then}\5
\&{return};\2\6
$\|n\K\\{info}(\|t)$;\5
$\|t\K\\{link}(\|t)$;\6
\&{if} $\|n=\\{generic\_subscript}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{subscr\_head\_loc}(\|p)$;\5
$\|q\K\\{link}(\|r)$;\C{$\|q=\\{subscr\_head}(\|p)$}\6
\&{while} $\\{name\_type}(\|q)=\\{subscr}$ \1\&{do}\6
\&{begin} \37$\\{flush\_variable}(\|q,\39\|t,\39\\{discard\_suffixes})$;\6
\&{if} $\|t=\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\|q)\I\\{structured}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|r)\K\\{link}(\|q)$;\5
$\\{free\_node}(\|q,\39\\{subscr\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{recycle\_value}(\\{attr\_head}(\|q))$;\5
$\|r\K\|q$;\6
\&{end}\2\6
\4\&{else} $\|r\K\|q$;\2\6
$\|q\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{end};\2\6
$\|p\K\\{attr\_head}(\|p)$;\6
\1\&{repeat} \37$\|r\K\|p$;\5
$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\\{info}(\|p)\G\|n$;\2\6
\&{if} $\\{info}(\|p)\I\|n$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\6
\&{if} $\\{discard\_suffixes}$ \1\&{then}\5
$\\{flush\_below\_variable}(\|p)$\6
\4\&{else} \&{begin} \37\&{if} $\\{type}(\|p)=\\{structured}$ \1\&{then}\5
$\|p\K\\{attr\_head}(\|p)$;\2\6
$\\{recycle\_value}(\|p)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M232. The next procedure is simpler; it wipes out everything but \|p itself,
which becomes undefined. We can also use it to clear the root of a
variable, by saying $\\{flush\_symbol}(\\{root})$.

\Y\P\D \37$\\{flush\_symbol}(\#)\S$\1\6
\&{begin} \37$\\{flush\_below\_variable}(\#)$;\5
$\\{free\_node}(\#,\39\\{value\_node\_size})$;\6
\&{end};\2\par
\Y\P$\4\X232:Declare the procedure called \\{flush\_below\_variable}\X\S$\6
\4\&{procedure}\1\  \37$\\{flush\_below\_variable}(\|p:\\{pointer})$;\2\6
\&{begin} \37\&{if} $\\{type}(\|p)\I\\{structured}$ \1\&{then}\5
$\\{recycle\_value}(\|p)$\C{this sets $\\{type}(\|p)=\\{undefined}$}\6
\4\&{else} \&{begin} \37$\|q\K\\{subscr\_head}(\|p)$;\6
\&{while} $\\{name\_type}(\|q)=\\{subscr}$ \1\&{do}\6
\&{begin} \37$\\{flush\_below\_variable}(\|q)$;\5
$\|r\K\|q$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{free\_node}(\|r,\39\\{subscr\_node\_size})$;\6
\&{end};\2\6
$\|r\K\\{attr\_head}(\|p)$;\5
$\|q\K\\{link}(\|r)$;\5
$\\{recycle\_value}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{value\_node\_size})$;\6
\1\&{repeat} \37$\\{flush\_below\_variable}(\|q)$;\5
$\|r\K\|q$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{free\_node}(\|r,\39\\{attr\_node\_size})$;\6
\4\&{until}\5
$\|q=\\{end\_attr}$;\2\6
$\\{type}(\|p)\K\\{undefined}$;\6
\&{end};\2\6
\&{end};\par
\U section~231.\fi

\N233.  \[xx] Saving and restoring equivalents.
The nested structure that is provided by \&{begingroup} and \&{endgroup}
allows \\{eqtb} entries to be saved and restored, so that temporary changes
can be made without difficulty.  When the user requests a current value to
be saved, \MF\ puts that value into its ``save stack.'' An appearance of
\&{endgroup} ultimately causes the old values to be removed from the save
stack and put back in their former places.

The save stack is a linked list containing three kinds of entries,
distinguished by their \\{info} fields. If \|p points to a saved item,
then

\smallskip\indent
$\\{info}(\|p)=0$ stands for a group boundary; \&{begingroup} contributes
such an item to the save stack and \&{endgroup} cuts back the stack
until the most recent such entry has been removed.

\smallskip\indent
$\\{info}(\|p)=\|q$, where $1\L\|q\L\\{hash\_size}$, means that $\\{mem}[%
\|p+1]$ holds the former
contents of $\\{eqtb}[\|q]$. Such entries are generated by \&{save} commands.

\smallskip\indent
$\\{info}(\|p)=\\{hash\_size}+\|q$, where $\|q>0$, means that $\\{value}(\|p)$
is a \\{scaled}
integer to be restored to internal parameter number~\|q. Such entries
are generated by \&{interim} commands.

\smallskip\noindent
The global variable \\{save\_ptr} points to the top item on the save stack.

\Y\P\D \37$\\{save\_node\_size}=2$\C{number of words per non-boundary
save-stack node}\par
\P\D \37$\\{saved\_equiv}(\#)\S\\{mem}[\#+1].\\{hh}$\C{where an \\{eqtb} entry
gets saved}\par
\P\D \37$\\{save\_boundary\_item}(\#)\S$\1\6
\&{begin} \37$\#\K\\{get\_avail}$;\5
$\\{info}(\#)\K0$;\5
$\\{link}(\#)\K\\{save\_ptr}$;\5
$\\{save\_ptr}\K\#$;\6
\&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{save\_ptr}: \37\\{pointer};\C{the most recently saved item}\par
\fi

\M234. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{save\_ptr}\K\\{null}$;\par
\fi

\M235. The \\{save\_variable} routine is given a hash address \|q; it salts
this
address in the save stack, together with its current equivalent,
then makes token~\|q behave as though it were brand new.

Nothing is stacked when $\\{save\_ptr}=\\{null}$, however; there's no way to
remove
things from the stack when the program is not inside a group, so there's
no point in wasting the space.

FIXTHIS: \\{tertiary\_secondary\_macro}, etc., needs to be flagged too!
The \\{flush\_symbol} routine ought to be beefed up.

\Y\P\4\&{procedure}\1\  \37$\\{save\_variable}(\|q:\\{pointer})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{temporary register}\2\6
\&{begin} \37\&{if} $\\{eq\_type}(\|q)=\\{name\_token}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{equiv}(\|q)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $\\{save\_ptr}\I\\{null}$ \1\&{then}\5
$\\{name\_type}(\|p)\K\\{saved\_root}$\6
\4\&{else} $\\{flush\_symbol}(\|p)$;\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{eq\_type}(\|q)=\\{defined\_macro}$ \1\&{then}\6
\&{if} $\\{save\_ptr}=\\{null}$ \1\&{then}\5
$\\{delete\_ref}(\\{equiv}(\|q))$;\2\2\2\6
\&{if} $\\{save\_ptr}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_node}(\\{save\_node\_size})$;\5
$\\{info}(\|p)\K\|q$;\5
$\\{link}(\|p)\K\\{save\_ptr}$;\5
$\\{saved\_equiv}(\|p)\K\\{eqtb}[\|q]$;\5
$\\{save\_ptr}\K\|p$;\6
\&{end};\2\6
$\\{eqtb}[\|q]\K\\{frozen\_undefined}$;\6
\&{end};\par
\fi

\M236. Similarly, \\{save\_internal} is given the location \|q of an internal
quantity like \\{tracing\_commands}. It creates a save stack entry of the
third kind.

\Y\P\4\&{procedure}\1\  \37$\\{save\_internal}(\|q:\\{small\_number})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{new item for the save stack}\2\6
\&{begin} \37\&{if} $\\{save\_ptr}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_node}(\\{save\_node\_size})$;\5
$\\{info}(\|p)\K\\{hash\_size}+\|q$;\5
$\\{link}(\|p)\K\\{save\_ptr}$;\5
$\\{value}(\|p)\K\\{internal}[\|q]$;\5
$\\{save\_ptr}\K\|p$;\6
\&{end};\2\6
\&{end};\par
\fi

\M237. At the end of a group, the \\{unsave} routine restores all of the saved
equivalents in reverse order. This routine will be called only when there
is at least one boundary item on the save stack.

\Y\P\4\&{procedure}\1\  \37\\{unsave};\6
\4\&{var} \37\|q: \37\\{pointer};\C{index to saved item}\6
\|p: \37\\{pointer};\C{temporary register}\2\6
\&{begin} \37\&{while} $\\{info}(\\{save\_ptr})\I0$ \1\&{do}\6
\&{begin} \37$\|q\K\\{info}(\\{save\_ptr})$;\6
\&{if} $\|q>\\{hash\_size}$ \1\&{then}\6
\&{begin} \37$\\{internal}[\|q-\\{hash\_size}]\K\\{value}(\\{save\_ptr})$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{eq\_type}(\|q)=\\{name\_token}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{equiv}(\|q)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{flush\_symbol}(\|p)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{eq\_type}(\|q)=\\{defined\_macro}$ \1\&{then}\5
$\\{delete\_ref}(\\{equiv}(\|q))$;\2\2\6
$\\{eqtb}[\|q]\K\\{saved\_equiv}(\\{save\_ptr})$;\6
\&{if} $\\{eq\_type}(\|q)=\\{name\_token}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{equiv}(\|q)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{name\_type}(\|p)\K\\{root}$;\2\6
\&{end};\2\6
\&{end};\2\6
$\|p\K\\{link}(\\{save\_ptr})$;\5
$\\{free\_node}(\\{save\_ptr},\39\\{save\_node\_size})$;\5
$\\{save\_ptr}\K\|p$;\6
\&{end};\2\6
$\|p\K\\{link}(\\{save\_ptr})$;\5
$\\{free\_avail}(\\{save\_ptr})$;\5
$\\{save\_ptr}\K\|p$;\6
\&{end};\par
\fi

\N238.  \[xx] Dynamic linear equations.
\MF\ users define variables implicitly by stating equations that should be
satisfied; the computer is supposed to be smart enough to solve those
equations.
And indeed, the computer tries valiantly to do so, by distinguishing five
different types of numeric values:

\smallskip\hang
$\\{type}(\|p)=\\{known}$ is the nice case, when $\\{value}(\|p)$ is the %
\\{scaled} value
of the variable addressed by~\|p.

\smallskip\hang
$\\{type}(\|p)=\\{dependent}$ means that $\\{value}(\|p)$ is not present, but $%
\\{dep\_list}(\|p)$
points to a {\sl dependency list\/} that expresses the value of variable~\|p
as a \\{scaled} number plus a sum of independent variables with \\{factor}
coefficients.

\smallskip\hang
$\\{type}(\|p)=\\{independent}$ means that $\\{value}(\|p)=\|m\G0$; each
dependent variable
that refers to this one is actually referring to the future value of
this variable times~$2↑m$. (Usually $\\{value}(\|p)=0$, but higher degrees of
scaling are sometimes needed to keep the coefficients in dependency lists
from getting too large. The value of~\|m will always be even.)

\smallskip\hang
$\\{type}(\|p)=\\{numeric\_type}$ means that variable \|p hasn't appeared in an
equation before, but it has been explicitly declared to be numeric.

\smallskip\hang
$\\{type}(\|p)=\\{undefined}$ means that variable \|p hasn't appeared before.

\smallskip\noindent
We have actually discussed these five types in the reverse order of their
history during a computation: Once \\{known}, a variable never again
becomes \\{dependent}; once \\{dependent}, it never again becomes
\\{independent}; once \\{independent}, it never again becomes \\{numeric%
\_type};
and once \\{numeric\_type}, it never again becomes \\{undefined} (except
of course when the user specifically decides to scrap the old value
and start again).

\fi

\M239. But how are dependency lists represented? Simple; the linear combination
$\alpha_1v_1+\cdots+\alpha_kv_k+\beta$ appears in $\|k+1$ value nodes. If
$\|q=\\{dep\_list}(\|p)$ points to this list, and if $\|k>0$, then $\\{value}(%
\|q)=\hbox{$\alpha_1$}$ (which is a \\{fraction}), $\\{info}(\|q)$ points to
the location
of $\alpha_1$, and $\\{link}(\|p)$ points to the dependency list
$\alpha_2v_2+\cdots+\alpha_kv_k+\beta$. On the other hand if $\|k=0$,
then $\\{value}(\|q)=\hbox{$\beta$}$ (which is \\{scaled}) and $\\{info}(\|q)=%
\\{null}$.
The independent variables $v_1$, \dots,~$v_k$ have been sorted so that
they appear in decreasing order of their locations in~\\{mem}.

The \\{link} field in the node that contains the constant term $\beta$ is
called the {\sl final link\/} of the dependency list. \MF\ maintains
a doubly-linked master list of all dependency lists, in terms of a special node
in \\{mem} called \\{dep\_head}. If there are no dependencies, we have
$\\{link}(\\{dep\_head})=\\{dep\_head}$ and $\\{prev\_dep}(\\{dep\_head})=%
\\{dep\_head}$;
otherwise $\\{link}(\\{dep\_head})$ points to the first dependent variable,
say~\|p,
and $\\{prev\_dep}(\|p)=\\{dep\_head}$. We have $\\{type}(\|p)=\\{dependent}$,
and $\\{dep\_list}(\|p)$
points to its dependency list. If the final link of that dependency list
occurs in location~\|q, then $\\{link}(\|q)$ points to the next dependent
variable (say~\|r); and $\\{prev\_dep}(\|r)=\|q$, etc.

\Y\P\D \37$\\{dep\_list}\S\\{attr\_head}$\C{half of the \\{value} field in a %
\\{dependent} variable}\par
\P\D \37$\\{prev\_dep}\S\\{subscr\_head}$\C{the other half; makes a doubly
linked list}\par
\P\D \37$\\{dep\_node\_size}=2$\C{the number of words per dependency node}\par
\Y\P$\4\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}\S$\6
$\\{link}(\\{dep\_head})\K\\{dep\_head}$;\5
$\\{prev\_dep}(\\{dep\_head})\K\\{dep\_head}$;\5
$\\{info}(\\{dep\_head})\K\\{null}$;\5
$\\{dep\_list}(\\{dep\_head})\K\\{null}$;\par
\fi

\M240. Actually the description above contains a little white lie. There's
another kind of variable called \\{proto\_dependent}, which is
just like a \\{dependent} one except that the $\alpha$ coefficients
in its dependency list are \\{scaled} instead of being fractions.
Proto-dependency lists are mixed with dependency lists in the
nodes reachable from \\{dep\_head}.

\fi

\M241. Here is a procedure that prints a dependency list in symbolic form.
The second parameter should be either \\{dependent} or \\{proto\_dependent},
to indicate the scaling of the coefficients.

\Y\P\4\&{procedure}\1\  \37$\\{print\_dependency}(\|p:\\{pointer},\39\|t:%
\\{small\_number})$;\6
\4\&{label} \37$\\{common\_ending},\39\\{exit}$;\6
\4\&{var} \37\|v: \37\\{integer};\C{a coefficient}\6
$\\{pp},\39\|q$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37$\\{pp}\K\|p$;\6
\~ \1\&{loop}\ \&{begin} \37$\|v\K\\{abs}(\\{value}(\|p))$;\5
$\|q\K\\{info}(\|p)$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\C{the constant term}\6
\&{begin} \37\&{if} $(\|v\I0)\V(\|p=\\{pp})$ \1\&{then}\6
\&{begin} \37\&{if} $\\{value}(\|p)>0$ \1\&{then}\6
\&{if} $\|p\I\\{pp}$ \1\&{then}\5
$\\{print\_char}(\.{"+"})$;\2\2\6
$\\{print\_scaled}(\\{value}(\|p))$;\6
\&{end};\2\6
\&{return};\6
\&{end};\2\6
\&{if} $\|t=\\{dependent}$ \1\&{then}\6
\&{begin} \37\&{if} $\|v\I\\{fraction\_one}$ \1\&{then}\6
\&{begin} \37$\\{print\_scaled}(\\{value}(\|p)\mathbin{\&{div}}\O{10000})$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\|v\I\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{print\_scaled}(\\{value}(\|p))$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\2\6
\&{if} $\\{value}(\|p)>0$ \1\&{then}\5
$\\{print\_char}(\.{"+"})$\ \&{else} $\\{print\_char}(\.{"-"})$;\2\6
\4\\{common\_ending}: \37\&{if} $\\{type}(\|p)\I\\{independent}$ \1\&{then}\5
$\\{confusion}(\.{"dep"})$;\2\6
$\\{print\_variable\_name}(\|q)$;\5
$\|v\K\\{value}(\|q)$;\6
\&{while} $\|v>0$ \1\&{do}\6
\&{begin} \37$\\{print}(\.{"*4"})$;\5
$\|v\K\|v-2$;\6
\&{end};\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M242. The maximum absolute value of a coefficient in a given dependency list
is returned by the following simple function.

\Y\P\4\&{function}\1\  \37$\\{max\_coef}(\|p:\\{pointer})$: \37\\{fraction};\6
\4\&{var} \37\|x: \37\\{fraction};\C{the maximum so far}\2\6
\&{begin} \37$\|x\K0$;\6
\&{while} $\\{info}(\|p)\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{abs}(\\{value}(\|p))>\|x$ \1\&{then}\5
$\|x\K\\{abs}(\\{value}(\|p))$;\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{max\_coef}\K\|x$;\6
\&{end};\par
\fi

\M243. One of the main operations needed on dependency lists is to add a
multiple
of one list to the other; we call this \\{p\_plus\_fq}, where \|p and~\|q point
to dependency lists and \|f is a fraction.

FIXTHIS: Check for $\|f=\\{fraction\_one}$ as simple case

If the coefficient of any independent variable becomes \\{coef\_threshold} or
more, in absolute value, this procedure changes the type of that variable
to `\\{independent\_needing\_fix}', and sets the global variable \\{fix%
\_needed}
to~\\{true}. The value of $\\{coef\_threshold}=\theta$ is chosen so that
$\theta↑2+\theta<8$; this means that the numbers we deal with won't
get too large. (Instead of the ``optimum'' $\theta=(\sqrt{33}-1)/2\approx
2.3723$, the safer value 7/3 is taken as the threshold.)

Several procedures that act on dependency lists also set the global
variable \\{dep\_tail} to the final (constant term) node of the dependency
list that they produce. (FIXTHIS: add this to other procedures when possible!)

\Y\P\D \37$\\{coef\_threshold}\S\O{4525252525}$\C{\\{fraction} approximation to
7/3}\par
\P\D \37$\\{independent\_needing\_fix}=0$\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{fix\_needed}: \37\\{boolean};\C{does at least one \\{independent} variable
need scaling?}\6
\4\\{dep\_tail}: \37\\{pointer};\C{location of the constant term and final
link}\par
\fi

\M244. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{fix\_needed}\K\\{false}$;\par
\fi

\M245. The \\{p\_plus\_fq} procedure has a fourth parameter, \|t, that should
be
set to \\{proto\_dependent} if \|p is a proto-dependency list. In this
case \|f will be \\{scaled}, not a \\{fraction}.

List \|q, which is always a true (non-proto) dependency list, is
unchanged by the operation; but list \|p is totally destroyed.

The final link of the dependency list or proto-dependency list returned
by \\{p\_plus\_fq} is the same as the original final link of~\|p. Indeed, the
constant term of the result will be located in the same \\{mem} location
as the original constant term of~\|p.

Coefficients of the result are assumed to be zero if they are less than
a certain threshold. This compensates for inevitable rounding errors,
and tends to make more variables `\\{known}'. The threshold is approximately
$10↑{-5}$ in the case of normal dependency lists, $10↑{-4}$ for
proto-dependencies.

\Y\P\D \37$\\{fraction\_threshold}=2685$\C{a \\{fraction} coefficient less than
this is zeroed}\par
\P\D \37$\\{half\_fraction\_threshold}=1342$\C{half of \\{fraction\_threshold}}%
\par
\P\D \37$\\{scaled\_threshold}=8$\C{a \\{scaled} coefficient less than this is
zeroed}\par
\P\D \37$\\{half\_scaled\_threshold}=4$\C{half of \\{scaled\_threshold}}\par
\Y\P\4\&{function}\1\  \37$\\{p\_plus\_fq}(\|p:\\{pointer};\,\35\|f:%
\\{integer};\,\35\|q:\\{pointer};\,\35\|t:\\{small\_number})$: \37\\{pointer};\6
\4\&{label} \37\\{done};\6
\4\&{var} \37$\\{pp},\39\\{qq}$: \37\\{pointer};\C{$\\{info}(\|p)$ and $%
\\{info}(\|q)$, respectively}\6
$\|r,\39\|s$: \37\\{pointer};\C{for list manipulation}\6
\\{threshold}: \37\\{integer};\C{defines a neighborhood of zero}\2\6
\&{begin} \37\&{if} $\|t=\\{dependent}$ \1\&{then}\5
$\\{threshold}\K\\{fraction\_threshold}$\6
\4\&{else} $\\{threshold}\K\\{scaled\_threshold}$;\2\6
$\|r\K\\{temp\_head}$;\5
$\\{pp}\K\\{info}(\|p)$;\5
$\\{qq}\K\\{info}(\|q)$;\6
\~ \1\&{loop}\6
\&{if} $\\{pp}=\\{qq}$ \1\&{then}\6
\&{if} $\\{pp}=\\{null}$ \1\&{then}\5
\&{goto} \37\\{done}\6
\4\&{else} \X246:Contribute a term from \|p plus \|f times the corresponding
term from \|q\X\2\6
\4\&{else} \&{if} $\\{pp}<\\{qq}$ \1\&{then}\5
\X247:Contribute a term from \|q, multiplied by~\|f\X\6
\4\&{else} \&{begin} \37$\\{link}(\|r)\K\|p$;\5
$\|r\K\|p$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{pp}\K\\{info}(\|p)$;\6
\&{end};\2\2\2\6
\4\\{done}: \37\&{if} $\|t=\\{dependent}$ \1\&{then}\5
$\\{value}(\|p)\K\\{value}(\|p)+\\{take\_fraction}(\\{value}(\|q),\39\|f)$\6
\4\&{else} $\\{value}(\|p)\K\\{value}(\|p)+\\{take\_scaled}(\\{value}(\|q),\39%
\|f)$;\2\6
$\\{dep\_tail}\K\|p$;\5
$\\{p\_plus\_fq}\K\\{link}(\\{temp\_head})$;\6
\&{end};\par
\fi

\M246. \P$\X246:Contribute a term from \|p plus \|f times the corresponding
term from \|q\X\S$\6
\&{begin} \37$\|v\K\\{value}(\|p)+\\{take\_fraction}(\|f,\39\\{value}(\|q))$;\5
$\\{value}(\|p)\K\|v$;\5
$\|s\K\|p$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{pp}\K\\{info}(\|p)$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{qq}\K\\{info}(\|q)$;\6
\&{if} $\\{abs}(\|v)<\\{threshold}$ \1\&{then}\5
$\\{free\_node}(\|s,\39\\{dep\_node\_size})$\6
\4\&{else} \&{begin} \37\&{if} $\\{abs}(\|v)\G\\{coef\_threshold}$ \1\&{then}\6
\&{begin} \37$\\{type}(\\{qq})\K\\{independent\_needing\_fix}$;\5
$\\{fix\_needed}\K\\{true}$;\6
\&{end};\2\6
$\\{link}(\|r)\K\|s$;\5
$\|r\K\|s$;\6
\&{end};\2\6
\&{end}\par
\U section~245.\fi

\M247. \P$\X247:Contribute a term from \|q, multiplied by~\|f\X\S$\6
\&{begin} \37$\|v\K\\{take\_fraction}(\|f,\39\\{value}(\|q))$;\6
\&{if} $\\{abs}(\|v)>\\{half}(\\{threshold})$ \1\&{then}\6
\&{begin} \37$\|s\K\\{get\_node}(\\{dep\_node\_size})$;\5
$\\{info}(\|s)\K\\{qq}$;\5
$\\{value}(\|s)\K\|v$;\6
\&{if} $\\{abs}(\|v)\G\\{coef\_threshold}$ \1\&{then}\6
\&{begin} \37$\\{type}(\\{qq})\K\\{independent\_needing\_fix}$;\5
$\\{fix\_needed}\K\\{true}$;\6
\&{end};\2\6
$\\{link}(\|r)\K\|s$;\5
$\|r\K\|s$;\6
\&{end};\2\6
\&{end}\par
\U section~245.\fi

\M248. A much simpler routine is needed when a user multiplies a dependency
list
by a given constant. The constant is either a \\{fraction} less than
\\{fraction\_one}, or it is \\{scaled}. In the latter case we might be forced
to
convert a dependency list to a proto-dependency list.
Parameters \\{t0} and \\{t1} are the list types before and after;
they should agree unless $\\{t0}=\\{dependent}$ and $\\{t1}=\\{proto%
\_dependent}$
and $\\{v\_is\_scaled}=\\{true}$.

\Y\P\4\&{function}\1\  \37$\\{p\_times\_v}(\|p:\\{pointer};\,\35\|v:%
\\{integer};\,\35\\{t0},\39\\{t1}:\\{small\_number};\,\35\\{v\_is\_scaled}:%
\\{boolean})$: \37\\{pointer};\6
\4\&{var} \37$\|r,\39\|s$: \37\\{pointer};\C{for list manipulation}\6
\|w: \37\\{integer};\C{tentative coefficient}\6
\\{threshold}: \37\\{integer};\5
\\{scaling\_down}: \37\\{boolean};\2\6
\&{begin} \37\&{if} $\\{t0}\I\\{t1}$ \1\&{then}\5
$\\{scaling\_down}\K\\{true}$\ \&{else} $\\{scaling\_down}\K\R\\{v\_is%
\_scaled}$;\2\6
\&{if} $\\{t1}=\\{dependent}$ \1\&{then}\5
$\\{threshold}\K\\{half\_fraction\_threshold}$\6
\4\&{else} $\\{threshold}\K\\{half\_scaled\_threshold}$;\2\6
$\|r\K\\{temp\_head}$;\6
\&{while} $\\{info}(\|p)\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{scaling\_down}$ \1\&{then}\5
$\|w\K\\{take\_fraction}(\|v,\39\\{value}(\|p))$\6
\4\&{else} $\|w\K\\{take\_scaled}(\|v,\39\\{value}(\|p))$;\2\6
\&{if} $\\{abs}(\|w)\L\\{threshold}$ \1\&{then}\6
\&{begin} \37$\|s\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{dep\_node\_size})$;\5
$\|p\K\|s$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{abs}(\|w)\G\\{coef\_threshold}$ \1\&{then}\6
\&{begin} \37$\\{fix\_needed}\K\\{true}$;\5
$\\{type}(\\{info}(\|p))\K\\{independent\_needing\_fix}$;\6
\&{end};\2\6
$\\{link}(\|r)\K\|p$;\5
$\|r\K\|p$;\5
$\\{value}(\|p)\K\|w$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{end};\2\6
$\\{link}(\|r)\K\|p$;\6
\&{if} $\\{v\_is\_scaled}$ \1\&{then}\5
$\\{value}(\|p)\K\\{take\_scaled}(\\{value}(\|p),\39\|v)$\6
\4\&{else} $\\{value}(\|p)\K\\{take\_fraction}(\\{value}(\|p),\39\|v)$;\2\6
$\\{p\_times\_v}\K\\{link}(\\{temp\_head})$;\6
\&{end};\par
\fi

\M249. Similarly, we sometimes need to divide a dependency list
by a given \\{scaled} constant.

\Y\P\4\&{function}\1\  \37$\\{p\_over\_v}(\|p:\\{pointer};\,\35\|v:\\{scaled};%
\,\35\\{t0},\39\\{t1}:\\{small\_number})$: \37\\{pointer};\6
\4\&{var} \37$\|r,\39\|s$: \37\\{pointer};\C{for list manipulation}\6
\|w: \37\\{integer};\C{tentative coefficient}\6
\\{threshold}: \37\\{integer};\5
\\{scaling\_down}: \37\\{boolean};\2\6
\&{begin} \37\&{if} $\\{t0}\I\\{t1}$ \1\&{then}\5
$\\{scaling\_down}\K\\{true}$\ \&{else} $\\{scaling\_down}\K\\{false}$;\2\6
\&{if} $\\{t1}=\\{dependent}$ \1\&{then}\5
$\\{threshold}\K\\{half\_fraction\_threshold}$\6
\4\&{else} $\\{threshold}\K\\{half\_scaled\_threshold}$;\2\6
$\|r\K\\{temp\_head}$;\6
\&{while} $\\{info}(\|p)\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{scaling\_down}$ \1\&{then}\5
$\|w\K\\{make\_scaled}(\\{value}(\|p)\mathbin{\&{div}}\O{10000},\39\|v)$\6
\4\&{else} $\|w\K\\{make\_scaled}(\\{value}(\|p),\39\|v)$;\2\6
\&{if} $\\{abs}(\|w)\L\\{threshold}$ \1\&{then}\6
\&{begin} \37$\|s\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{dep\_node\_size})$;\5
$\|p\K\|s$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{abs}(\|w)\G\\{coef\_threshold}$ \1\&{then}\6
\&{begin} \37$\\{fix\_needed}\K\\{true}$;\5
$\\{type}(\\{info}(\|p))\K\\{independent\_needing\_fix}$;\6
\&{end};\2\6
$\\{link}(\|r)\K\|p$;\5
$\|r\K\|p$;\5
$\\{value}(\|p)\K\|w$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{end};\2\6
$\\{link}(\|r)\K\|p$;\5
$\\{value}(\|p)\K\\{make\_scaled}(\|v,\39\\{value}(\|p))$;\5
$\\{p\_over\_v}\K\\{link}(\\{temp\_head})$;\6
\&{end};\par
\fi

\M250. Here's another utility routine for dependency lists. When an independent
variable becomes dependent, we want to remove it from all existing
dependencies. The \\{p\_with\_x\_becoming\_q} function computes the
dependency list of~\|p after variable~\|x has been replaced by~\|q.

This procedure has the same calling conventions as \\{p\_plus\_fq}. List~\|q
is unchanged; list~\|p is destroyed; the constant node and the final link
are inherited from~\|p; and the fourth parameter tells whether or
not \|p is \\{proto\_dependent}.

\Y\P\4\&{function}\1\  \37$\\{p\_with\_x\_becoming\_q}(\|p:\\{pointer};\,\35%
\|f:\\{integer};\,\35\|q:\\{pointer};\,\35\|t:\\{small\_number})$: \37%
\\{pointer};\6
\4\&{var} \37$\|r,\39\|s$: \37\\{pointer};\C{for list manipulation}\6
\|v: \37\\{integer};\C{coefficient of \|x}\2\6
\&{begin} \37$\|s\K\|p$;\5
$\|r\K\\{temp\_head}$;\6
\&{while} $\\{info}(\|s)>\|q$ \1\&{do}\6
\&{begin} \37$\|r\K\|s$;\5
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
\&{if} $\\{info}(\|s)\I\|q$ \1\&{then}\5
$\\{p\_with\_x\_becoming\_q}\K\|p$\6
\4\&{else} \&{begin} \37$\\{link}(\\{temp\_head})\K\|p$;\5
$\\{link}(\|r)\K\\{link}(\|s)$;\5
$\|v\K\\{value}(\|s)$;\5
$\\{free\_node}(\|s,\39\\{dep\_node\_size})$;\5
$\\{p\_with\_x\_becoming\_q}\K\\{p\_plus\_fq}(\\{link}(\\{temp\_head}),\39\|v,%
\39\|q,\39\|t)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M251. The \\{fix\_dependencies} routine is called into action when \\{fix%
\_needed}
has been triggered. The program keeps a list~\|s of independent variables
whose coefficients must be scaled down.

\Y\P\D \37$\\{independent\_being\_fixed}=1$\C{this variable already appears in %
\|s}\par
\Y\P\4\&{procedure}\1\  \37\\{fix\_dependencies};\6
\4\&{var} \37$\|p,\39\|r,\39\|s$: \37\\{pointer};\C{list manipulation
registers}\6
\|x: \37\\{pointer};\C{an independent variable}\2\6
\&{begin} \37$\|r\K\\{link}(\\{dep\_head})$;\5
$\|s\K\\{null}$;\6
\&{while} $\|r\I\\{dep\_head}$ \1\&{do}\6
\&{begin} \37$\|r\K\\{dep\_list}(\|r)$;\6
\~ \1\&{loop}\ \&{begin} \37$\|x\K\\{info}(\|r)$;\6
\&{if} $\|x=\\{null}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{type}(\|x)\L\\{independent\_being\_fixed}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{type}(\|x)<\\{independent\_being\_fixed}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{link}(\|p)\K\|s$;\5
$\|s\K\|p$;\5
$\\{info}(\|s)\K\|x$;\5
$\\{type}(\|x)\K\\{independent\_being\_fixed}$;\6
\&{end};\2\6
$\\{value}(\|r)\K\\{value}(\|r)\mathbin{\&{div}}4$;\6
\&{end};\2\6
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\4\\{done}: \37$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{while} $\|s\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|p\K\\{link}(\|s)$;\5
$\|x\K\\{info}(\|s)$;\5
$\\{free\_avail}(\|s)$;\5
$\|s\K\|p$;\5
$\\{type}(\|x)\K\\{independent}$;\5
$\\{value}(\|x)\K\\{value}(\|x)+2$;\6
\&{end};\2\6
\&{end};\par
\fi

\M252. But how do variables become known? Ah, now we get to the heart of
the equation-solving mechanism. The \\{new\_eq} procedure is given two
proto-dependency lists, \\{lhs} and \\{rhs}; it updates the existing
variables based on the equation $\\{lhs}=\\{rhs}$. The \\{lhs} variable should
not be in the list of existing dependencies, but the \\{rhs} variable
should be in that list; \\{lhs} is destroyed in the process.

The idea is simple: We equate $\\{lhs}-\\{rhs}$ to zero, and this should yield
a linear dependency between some of the independent variables.
The independent variable with the largest coefficient is made dependent
on the others and eliminated from all current dependencies. This
elimination might make other dependent variables known.

\Y\P\4\&{procedure}\1\  \37$\\{new\_eq}(\\{lhs},\39\\{rhs}:\\{pointer})$;\6
\4\&{label} \37\\{exit}; \6
\4\&{var} \37\&{begin} \37$\|p\K\\{p\_plus\_fq}(\\{lhs},\39-\\{unity},\39%
\\{rhs},\39\\{proto\_dependent})$;\6
\&{if} $\\{info}(\|p)=\\{null}$ \1\&{then}\5
\X253:Print an error message and \&{return}, since no independent variables
remain in the equation\X;\2\6
\X254:Find the node \|q in list \|p whose coefficient \|v is largest\X;\6
$\|x\K\\{info}(\|q)$;\5
$\|n\K\\{value}(\|x)$;\6
\X255:Divide list \|p by $-\|v$, removing node \|q\X;\6
\&{if} $\\{internal}[\\{tracing\_equations}]$ \1\&{then}\5
\X256:Display the new dependency\X;\2\6
\X257:Simplify all existing dependencies by substituting for \|x\X;\6
\X259:Change variable \|x from \\{independent} to \\{dependent} or \\{known}\X;%
\6
\&{if} $\\{fix\_needed}$ \1\&{then}\5
\\{fix\_dependencies};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M253. \P$\X253:Print an error message and \&{return}, since no independent
variables remain in the equation\X\S$\6
\&{begin} \37\&{if} $\\{abs}(\\{value}(\|p))\G\\{scaled\_threshold}$ \1\&{then}%
\6
\&{begin} \37$\\{print\_err}(\.{"Inconsistent\ equation"})$;\5
$\\{help2}(\.{"This\ equation\ contradicts\ what\ you\ said\ before."})$\6
$(\.{"But\ don\'t\ worry;\ continue\ and\ I\'ll\ just\ ignore\ it."})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Redundant\ equation"})$;\5
$\\{help2}(\.{"I\ already\ knew\ that\ this\ equation\ was\ true."})$\6
$(\.{"But\ perhaps\ no\ harm\ has\ been\ done;\ let\'s\ continue."})$;\6
\&{end};\2\6
\\{error};\5
$\\{free\_node}(\|p,\39\\{dep\_node\_size})$;\5
\&{return};\6
\&{end}\par
\U section~252.\fi

\M254. \P$\X254:Find the node \|q in list \|p whose coefficient \|v is largest%
\X\S$\6
$\|q\K\|p$;\5
$\|r\K\\{link}(\|p)$;\5
$\|v\K\\{value}(\|q)$;\6
\&{while} $\\{info}(\|r)\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{abs}(\\{value}(\|r))>\\{abs}(\|v)$ \1\&{then}\6
\&{begin} \37$\|q\K\|r$;\5
$\|v\K\\{value}(\|r)$;\6
\&{end};\2\6
$\|r\K\\{link}(\|r)$;\6
\&{end}\2\par
\U section~252.\fi

\M255. Here we want to change the coefficients from \\{scaled} to \\{fraction},
except in the constant term. In the common case of a trivial equation
like `\.{x=3.14}', we will have $\|v=\\{unity}$ and $\|q=\|p$.

\Y\P$\4\X255:Divide list \|p by $-\|v$, removing node \|q\X\S$\6
$\|s\K\\{temp\_head}$;\5
$\\{link}(\|s)\K\|p$;\5
$\|r\K\|p$;\6
\1\&{repeat} \37\&{if} $\|r=\|q$ \1\&{then}\6
\&{begin} \37$\\{link}(\|s)\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{dep\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|w\K\\{make\_fraction}(\\{value}(\|r),\39\|v)$;\6
\&{if} $\\{abs}(\|w)\L\\{half\_fraction\_threshold}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|s)\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{dep\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{value}(\|r)\K-\|w$;\5
$\|s\K\|r$;\6
\&{end};\2\6
\&{end};\2\6
$\|r\K\\{link}(\|s)$;\6
\4\&{until}\5
$\\{info}(\|r)=\\{null}$;\2\6
\&{if} $\|v=\\{unity}$ \1\&{then}\5
$\\{negate}(\\{value}(\|r))$\6
\4\&{else} $\\{value}(\|r)\K\\{take\_fraction}(\\{value}(\|r),\39\\{make%
\_fraction}(-\\{unity},\39\|v))$;\2\6
$\|p\K\\{link}(\\{temp\_head})$\par
\U section~252.\fi

\M256. \P$\X256:Display the new dependency\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{"\#\#\ "})$;\5
$\\{print\_variable\_name}(\|x)$;\5
$\|w\K\|n$;\6
\&{while} $\|w>0$ \1\&{do}\6
\&{begin} \37$\\{print}(\.{"*4"})$;\5
$\|w\K\|w-2$;\6
\&{end};\2\6
$\\{print\_char}(\.{"="})$;\5
$\\{print\_dependency}(\|p,\39\\{dependent})$;\6
\&{end}\par
\U section~252.\fi

\M257. \P$\X257:Simplify all existing dependencies by substituting for \|x\X\S$%
\6
$\\{prev\_r}\K\\{dep\_head}$;\5
$\|r\K\\{link}(\\{dep\_head})$;\6
\&{while} $\|r\I\\{dep\_head}$ \1\&{do}\6
\&{begin} \37$\|s\K\\{dep\_list}(\|r)$;\5
$\|q\K\\{p\_with\_x\_becoming\_q}(\|s,\39\|x,\39\|p,\39\\{type}(\|r))$;\6
\&{if} $(\\{info}(\|q)=\\{null})\W(\\{type}(\|r)=\\{dependent})$ \1\&{then}\5
\X258:Change variable \|r from \\{dependent} to \\{known}\X\6
\4\&{else} \&{begin} \37$\\{dep\_list}(\|r)\K\|q$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|q)$;\6
\4\&{until}\5
$\\{info}(\|q)=\\{null}$;\2\6
$\\{prev\_r}\K\|q$;\5
$\|r\K\\{link}(\|q)$;\6
\&{end};\2\6
\&{end}\2\par
\U section~252.\fi

\M258. FIXTHIS: I should also allow \\{proto\_dependent} variables to become %
\\{known}!

\Y\P$\4\X258:Change variable \|r from \\{dependent} to \\{known}\X\S$\6
\&{begin} \37$\\{type}(\|r)\K\\{known}$;\5
$\\{value}(\|r)\K\\{value}(\|q)$;\6
\&{if} $\\{internal}[\\{tracing\_equations}]>0$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"\#\#\#\#\ "})$;\5
$\\{print\_variable\_name}(\|r)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_scaled}(\\{value}(\|r))$;\6
\&{end};\2\6
$\|r\K\\{link}(\|q)$;\5
$\\{prev\_dep}(\|r)\K\\{prev\_r}$;\5
$\\{link}(\\{prev\_r})\K\|r$;\5
$\\{free\_node}(\|q,\39\\{dep\_node\_size})$;\6
\&{end}\par
\U section~257.\fi

\M259. \P$\X259:Change variable \|x from \\{independent} to \\{dependent} or %
\\{known}\X\S$\6
\&{if} $\|n>0$ \1\&{then}\5
\X260:Divide list \|p by $2↑n$\X;\2\6
\&{if} $\\{info}(\|p)=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{type}(\|x)\K\\{known}$;\5
$\\{value}(\|x)\K\\{value}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{dep\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{type}(\|x)\K\\{dependent}$;\5
$\\{dep\_list}(\|x)\K\|p$;\5
$\\{prev\_dep}(\|x)\K\\{dep\_head}$;\5
$\|q\K\|p$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|q)$;\6
\4\&{until}\5
$\\{info}(\|q)=\\{null}$;\2\6
$\\{link}(\|q)\K\\{link}(\\{dep\_head})$;\5
$\\{prev\_dep}(\\{link}(\\{dep\_head}))\K\|q$;\5
$\\{link}(\\{dep\_head})\K\|x$;\6
\&{end}\2\par
\U section~252.\fi

\M260. \P$\X260:Divide list \|p by $2↑n$\X\S$\6
\&{begin} \37$\|s\K\\{temp\_head}$;\5
$\\{link}(\|s)\K\|p$;\5
$\|r\K\|p$;\6
\1\&{repeat} \37\&{if} $\|n>30$ \1\&{then}\5
$\|w\K0$\6
\4\&{else} $\|w\K\\{value}(\|r)\mathbin{\&{div}}\\{two\_to\_the}[\|n]$;\2\6
\&{if} $(\\{abs}(\|w)\L\\{half\_fraction\_threshold})\W(\\{info}(\|r)\I%
\\{null})$ \1\&{then}\6
\&{begin} \37$\\{link}(\|s)\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{dep\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{value}(\|r)\K\|w$;\5
$\|s\K\|r$;\6
\&{end};\2\6
$\|r\K\\{link}(\|s)$;\6
\4\&{until}\5
$\\{info}(\|s)=\\{null}$;\2\6
$\|p\K\\{link}(\\{temp\_head})$;\6
\&{end}\par
\U section~259.\fi

\N261.  \[xx] Dynamic nonlinear equations.
Variables of numeric type are maintained by the general scheme of
independent, dependent, and known values that we have just studied;
and the components of pair and transform variables are handled in the
same way. But \MF\ also has five other types of values: \&{boolean},
\&{string}, \&{pen}, \&{path}, and \&{edges}; what about them?

Equations are allowed between nonlinear quantities, but only in a
simple form. Two variables that haven't yet been assigned values are
either equal to each other, or they're not.

Before a boolean variable has received a value, its type is \\{unknown%
\_boolean};
similarly, there are variables whose type is \\{unknown\_string}, \\{unknown%
\_pen},
\\{unknown\_path}, and \\{unknown\_edges}. In such cases the value is either
\\{null} (which means that no other variables are equivalent to this one), or
it points to another variable of the same undefined type. The pointers in the
latter case form a cycle of nodes, which we shall call a ``ring.''

Rings of undefined variables may include capsules, which arise as
intermediate results within expressions or as \&{expr} parameters to macros.
However, each ring contains at least one non-capsule.

When one member of a ring receives a value, the same value is given to
all the other members. In the case of paths and edges, this implies
making separate copies of a potentially large data structure; users should
restrain their enthusiasm for such generality, unless they have lots and
lots of memory space.

\fi

\M262. The following procedure is called when a capsule node is being
added to a ring (e.g., when an unknown variable is mentioned in an expression).

\Y\P\4\&{function}\1\  \37$\\{new\_ring\_entry}(\|p:\\{pointer})$: \37%
\\{pointer};\6
\4\&{var} \37\|q: \37\\{pointer};\C{the new capsule node}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{name\_type}(\|q)\K\\{capsule}$;\5
$\\{type}(\|q)\K\\{type}(\|p)$;\6
\&{if} $\\{value}(\|p)=\\{null}$ \1\&{then}\5
$\\{value}(\|q)\K\|p$\ \&{else} $\\{value}(\|q)\K\\{value}(\|p)$;\2\6
$\\{value}(\|p)\K\|q$;\5
$\\{new\_ring\_entry}\K\|q$;\6
\&{end};\par
\fi

\N263.  \[xx] Data structures for paths.
When a \MF\ user specifies a path, \MF\ will create a list of knots
and control points for the associated cubic spline curves. If the
knots are $z_0$, $z_1$, \dots, $z_n$, there are control points
$z_k↑+$ and $z_{k+1}↑-$ such that the cubic splines between knots
$z_k$ and $z_{k+1}$ are defined by B\'ezier's formula
$$\eqalign{z(t)&=B(z_k,z_k↑+,z_{k+1}↑-,z_{k+1};t)\cr
&=(1-t)↑3z_k+3(1-t)↑2tz_k↑++3(1-t)t↑2z_{k+1}↑-+t↑3z_{k+1}\cr}$$
for $0\L\|t\L1$.

There is a 7-word node for each knot $z_k$, containing one word of
control information and six words for the \|x and \|y coordinates
of $z_k↑-$ and $z_k$ and~$z_k↑+$. The control information appears
in the \\{left\_type} and \\{right\_type} fields, which each occupy
a quarter of the first word in the node; they specify properties
of the curve as it enters and leaves the knot. There's also a
halfword \\{link} field, which points to the following knot.

If the path is a closed contour, knots 0 and \|n are identical;
i.e., the \\{link} in knot $\|n-1$ points to knot~0. But if the path
is not closed, \\{left\_type} of knot~0 and \\{right\_type} of knot~\|n
are \\{endpoint}. In the latter case the \\{link} in knot~\|n points
to knot~0, and the control points $z_0↑-$ and $z_n↑+$ are not used.

\Y\P\D \37$\\{left\_type}(\#)\S\\{mem}[\#].\\{hh}.\\{b0}$\C{characterizes the
path entering this knot}\par
\P\D \37$\\{right\_type}(\#)\S\\{mem}[\#].\\{hh}.\\{b1}$\C{characterizes the
path leaving this knot}\par
\P\D \37$\\{endpoint}=0$\C{\\{left\_type} at path beginning and \\{right\_type}
at path end}\par
\P\D \37$\\{x\_coord}(\#)\S\\{mem}[\#+1].\\{sc}$\C{the \|x coordinate of this
knot}\par
\P\D \37$\\{y\_coord}(\#)\S\\{mem}[\#+2].\\{sc}$\C{the \|y coordinate of this
knot}\par
\P\D \37$\\{left\_x}(\#)\S\\{mem}[\#+3].\\{sc}$\C{the \|x coordinate of
previous control point}\par
\P\D \37$\\{left\_y}(\#)\S\\{mem}[\#+4].\\{sc}$\C{the \|y coordinate of
previous control point}\par
\P\D \37$\\{right\_x}(\#)\S\\{mem}[\#+5].\\{sc}$\C{the \|x coordinate of next
control point}\par
\P\D \37$\\{right\_y}(\#)\S\\{mem}[\#+6].\\{sc}$\C{the \|y coordinate of next
control point}\par
\P\D \37$\\{knot\_size}=7$\C{number of words in a knot node}\par
\fi

\M264. Before the B\'ezier control points have been calculated, the memory
space they will ultimately occupy is taken up by information that can be
used to compute them. There are four cases:

\yskip
\textindent{$\bullet$} If $\\{right\_type}=\\{open}$, the curve should leave
the knot in the same direction it entered; \MF\ will figure out a
suitable direction.

\yskip
\textindent{$\bullet$} If $\\{right\_type}=\\{curl}$, the curve should leave
the
knot in a direction depending on the angle at which it enters the next
knot and the curl parameter stored in \\{right\_curl}.

\yskip
\textindent{$\bullet$} If $\\{right\_type}=\\{given}$, the curve should leave
the
knot in a nonzero direction found in the \\{x\_coord} and \\{y\_coord} fields
of a 3-word node pointed to by \\{right\_given}.

\yskip
\textindent{$\bullet$} If $\\{right\_type}=\\{explicit}$, the B\'ezier control
point for leaving this knot has already been computed; it is in the
\\{right\_x} and \\{right\_y} fields.

\yskip\noindent
The rules for \\{left\_type} are similar, but they refer to the curve entering
the knot, and to \\{left\_} fields instead of \\{right\_} fields.

Non-\\{explicit} control points will be chosen based on ``tension'' parameters
stored in the \\{left\_tension} and \\{right\_tension} fields.

For example, the \MF\ path specification
$$\.{z0..z1..z2\{curl 2\}\&z2..z3\{-1,-2\}..tension 3 and 4..p},$$
where \.p is the path `\.{z4..controls z45 and z54..z5}', will be represented
by the six knots
$$\vbox{\halign{#\hfil&&\qquad#\hfil\cr
\\{left\_type}&\\{left} info&$\\{x\_coord},\\{y\_coord}$&\\{right\_type}&%
\\{right} info\cr
\noalign{\yskip}
\\{endpoint}&---$,\,$---&$x_0,y_0$&\\{curl}&$1.0,1.0$\cr
\\{open}&---$,1.0$&$x_1,y_1$&\\{open}&---$,1.0$\cr
\\{curl}&$2.0,1.0$&$x_2,y_2$&\\{curl}&$1.0,1.0$\cr
\\{given}&$q,1.0$&$x_3,y_3$&\\{given}&$q,3.0$\cr
\\{open}&---$,4.0$&$x_4,y_4$&\\{explicit}&$x_{45},y_{45}$\cr
\\{explicit}&$x_{54},y_{54}$&$x_5,y_5$&\\{endpoint}&---$,\,$---\cr}}$$
Here \|q is a 3-word node containing $\\{x\_coord}=-1.0$ and $\\{y%
\_coord}=-2.0$.
Of course, this example is more complicated than anything a normal user
would ever write.

These types must satisfy certain restrictions because of the form of \MF's
path syntax:
(i)~\\{endpoint} and \\{open} types never appear together in the same node.
(ii)~\\{open} and \\{given} types never appear together in the same node.
(iii)~\\{open} and \\{curl} types never appear together in the same node.
(iv)~The \\{right\_type} of a node is \\{explicit} if and only if the
\\{left\_type} of the following node is \\{explicit}.
(v)~\\{endpoint} types occur only at the ends, as mentioned above.

\Y\P\D \37$\\{left\_curl}\S\\{left\_x}$\C{curl information when entering this
knot}\par
\P\D \37$\\{left\_given}\S\\{left\_x}$\C{pointer to given direction when
entering this knot}\par
\P\D \37$\\{left\_tension}\S\\{left\_y}$\C{tension information when entering
this knot}\par
\P\D \37$\\{right\_curl}\S\\{right\_x}$\C{curl information when leaving this
knot}\par
\P\D \37$\\{right\_given}\S\\{right\_x}$\C{pointer to given direction when
leaving this knot}\par
\P\D \37$\\{right\_tension}\S\\{right\_y}$\C{tension information when leaving
this knot}\par
\P\D \37$\\{coord\_node\_size}=3$\C{size of nodes pointed to by \\{left%
\_given}, \\{right\_given}}\par
\P\D \37$\\{explicit}=1$\C{\\{left\_type} or \\{right\_type} when control
points are known}\par
\P\D \37$\\{given}=2$\C{\\{left\_type} or \\{right\_type} when a direction is
given}\par
\P\D \37$\\{curl}=3$\C{\\{left\_type} or \\{right\_type} when a curl is
desired}\par
\P\D \37$\\{open}=4$\C{\\{left\_type} or \\{right\_type} when \MF\ should
choose the direction}\par
\fi

\M265. When a path is being formed, \MF\ delas with single-node fragments that
specify only a point and a direction. (This arises only at the ``tertiary''
level of parsing.) In such cases the \\{left\_type} is \\{fragment}, and the
\\{right\_type} is either \\{given} or \\{curl}; in the case of \\{given},
a given direction appears in \\{right\_x} and \\{right\_y}.

\Y\P\D \37$\\{fragment}=5$\C{\\{left\_type} in a path fragment}\par
\fi

\M266. Here is a diagnostic routine that prints a given knot list
in symbolic form. It illustrates the conventions discussed above,
and checks for anomalies that might arise while \MF\ is being debugged.

\Y\P\4\&{procedure}\1\  \37$\\{print\_path}(\|h:\\{pointer};\,\35\|s:\\{str%
\_number})$;\6
\4\&{label} \37$\\{done},\39\\{done1}$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list traversal}\2\6
\&{begin} \37$\\{print\_diagnostic}(\.{"Path"},\39\|s)$;\6
\&{if} $\\{left\_type}(\|h)=\\{fragment}$ \1\&{then}\5
\X267:Display a fragment and \&{goto} \\{done}\X;\2\6
$\|p\K\|h$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|p)$;\6
\&{if} $(\|p=\\{null})\V(\|q=\\{null})$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Unexpected\ end\ of\ path!"})$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\X268:Print information for adjacent knots \|p and \|q\X;\6
$\|p\K\|q$;\6
\&{if} $\|p\I\|h$ \1\&{then}\5
$\\{print\_nl}(\.{"\ .."})$;\2\6
\4\&{until}\5
$\|p=\|h$;\2\6
\&{if} $\\{left\_type}(\|h)\I\\{endpoint}$ \1\&{then}\5
$\\{print\_nl}(\.{"\ ..cycle"})$;\2\6
\4\\{done}: \37$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\par
\fi

\M267. \P$\X267:Display a fragment and \&{goto} \\{done}\X\S$\6
\&{begin} \37$\\{print\_two}(\\{x\_coord}(\|h),\39\\{y\_coord}(\|h))$;\6
\&{if} $\\{right\_type}(\|h)=\\{curl}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\{curl\ "})$;\5
$\\{print\_scaled}(\\{right\_curl}(\|h))$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_char}(\.{"\{"})$;\5
$\\{print\_scaled}(\\{right\_x}(\|h))$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\\{right\_y}(\|h))$;\6
\&{end};\2\6
$\\{print\_char}(\.{"\}"})$;\5
\&{goto} \37\\{done};\6
\&{end}\par
\U section~266.\fi

\M268. \P$\X268:Print information for adjacent knots \|p and \|q\X\S$\6
$\\{print\_two}(\\{x\_coord}(\|p),\39\\{y\_coord}(\|p))$;\6
\&{if} $\\{right\_type}(\|p)\L\\{explicit}$ \1\&{then}\5
\X269:Print previous \\{given} or \\{curl}\X;\2\6
\&{case} $\\{right\_type}(\|p)$ \1\&{of}\6
\4\\{endpoint}: \37\&{begin} \37\&{if} $\\{left\_type}(\|p)=\\{open}$ \1%
\&{then}\5
$\\{print}(\.{"\{open?\}"})$;\C{can't happen}\2\6
\&{if} $(\\{left\_type}(\|q)\I\\{endpoint})\V(\|q\I\|h)$ \1\&{then}\5
$\|q\K\\{null}$;\C{force an error}\2\6
\&{goto} \37\\{done1};\6
\&{end};\6
\4\\{explicit}: \37\X271:Print control points between \|p and \|q, then %
\&{goto} \\{done1}\X;\6
\4\\{open}: \37\X272:Print information for a curve that begins \\{open}\X;\6
\4$\\{curl},\39\\{given}$: \37\X273:Print information for a curve that begins %
\\{curl} or \\{given}\X;\6
\4\&{othercases} \37$\\{print}(\.{"\{unknown\ type!\}"})$\2\6
\&{endcases};\6
\&{if} $\\{left\_type}(\|q)\L\\{explicit}$ \1\&{then}\5
$\\{print}(\.{"..control?"})$\C{can't happen}\6
\4\&{else} \&{if} $(\\{right\_tension}(\|p)\I\\{unity})\V(\\{left\_tension}(%
\|q)\I\\{unity})$ \1\&{then}\5
\X270:Print tension between \|p and \|q\X;\2\2\6
\4\\{done1}: \37\par
\U section~266.\fi

\M269. \P$\X269:Print previous \\{given} or \\{curl}\X\S$\6
\&{if} $\\{left\_type}(\|p)=\\{given}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{left\_given}(\|p)$;\5
$\\{print\_char}(\.{"\{"})$;\5
$\\{print\_scaled}(\\{x\_coord}(\|r))$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\\{y\_coord}(\|r))$;\5
$\\{print\_char}(\.{"\}"})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{left\_type}(\|p)=\\{curl}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\{curl\ "})$;\5
$\\{print\_scaled}(\\{left\_curl}(\|p))$;\5
$\\{print\_char}(\.{"\}"})$;\6
\&{end}\2\2\par
\U sections~268 and~273.\fi

\M270. \P$\X270:Print tension between \|p and \|q\X\S$\6
\&{begin} \37$\\{print}(\.{"..tension\ "})$;\5
$\\{print\_scaled}(\\{right\_tension}(\|p))$;\6
\&{if} $\\{right\_tension}(\|p)\I\\{left\_tension}(\|q)$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ and\ "})$;\5
$\\{print\_scaled}(\\{left\_tension}(\|q))$;\6
\&{end};\2\6
\&{end}\par
\U section~268.\fi

\M271. \P$\X271:Print control points between \|p and \|q, then \&{goto} %
\\{done1}\X\S$\6
\&{begin} \37$\\{print}(\.{"\ ..controls\ "})$;\5
$\\{print\_two}(\\{right\_x}(\|p),\39\\{right\_y}(\|p))$;\5
$\\{print}(\.{"\ and\ "})$;\6
\&{if} $\\{left\_type}(\|q)\I\\{explicit}$ \1\&{then}\5
$\\{print}(\.{"??"})$\C{can't happen}\6
\4\&{else} $\\{print\_two}(\\{left\_x}(\|q),\39\\{left\_y}(\|q))$;\2\6
\&{goto} \37\\{done1};\6
\&{end}\par
\U section~268.\fi

\M272. \P$\X272:Print information for a curve that begins \\{open}\X\S$\6
\&{if} $(\\{left\_type}(\|p)\I\\{explicit})\W(\\{left\_type}(\|p)\I\\{open})$ %
\1\&{then}\5
$\\{print}(\.{"\{open?\}"})$\C{can't happen}\2\par
\U section~268.\fi

\M273. A curl of 1 is shown explicitly, so that the user sees clearly that
\MF's default curl is present.

The code here uses the fact that $\\{left\_curl}\S\\{left\_given}$ and
$\\{right\_curl}\S\\{right\_given}$.

\Y\P$\4\X273:Print information for a curve that begins \\{curl} or \\{given}\X%
\S$\6
\&{begin} \37\&{if} $\\{left\_type}(\|p)\G\\{given}$ \1\&{then}\6
\&{if} $\\{left\_type}(\|p)=\\{open}$ \1\&{then}\5
$\\{print}(\.{"??"})$\C{can't happen}\6
\4\&{else} \&{if} $(\\{left\_type}(\|p)\I\\{right\_type}(\|p))\V(\\{left%
\_curl}(\|p)\I\\{right\_curl}(\|p))$ \1\&{then}\6
\&{begin} \37\X269:Print previous \\{given} or \\{curl}\X;\6
$\\{print\_char}(\.{"\&"})$;\5
$\\{print\_two}(\\{x\_coord}(\|p),\39\\{y\_coord}(\|p))$;\6
\&{end};\2\2\2\6
\&{if} $\\{right\_type}(\|p)=\\{curl}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\{curl\ "})$;\5
$\\{print\_scaled}(\\{right\_curl}(\|p))$;\5
$\\{print\_char}(\.{"\}"})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|r\K\\{right\_given}(\|p)$;\5
$\\{print\_char}(\.{"\{"})$;\5
$\\{print\_scaled}(\\{x\_coord}(\|r))$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\\{y\_coord}(\|r))$;\5
$\\{print\_char}(\.{"\}"})$;\6
\&{end};\2\6
\&{end}\par
\U section~268.\fi

\M274. When a list of knot nodes is no longer needed, it can be recycled by
calling the following subroutine.

\Y\P\4\&{procedure}\1\  \37$\\{toss\_knot\_list}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the node being freed}\2\6
\&{begin} \37\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{link}(\|q)$;\5
$\\{free\_node}(\|q,\39\\{knot\_size})$;\6
\&{end};\2\6
\&{end};\par
\fi

\N275.  \[xx] Choosing control points.
Now we must actually delve into one of \MF's more difficult routines,
the \\{make\_choices} procedure that chooses angles and control points for
the splines of a curve when the user has not specified them explicitly.

The first parameter to \\{make\_choices} points to a list of knots and
path information, as described above; the second parameter points to a
list of coordinate nodes that will be returned to available memory
after all of the control points have been chosen.

A path decomposes into independent segments at ``breakpoint'' knots,
which are knots whose left and right angles are both prespecified in
some way (i.e., their \\{left\_type} and \\{right\_type} aren't both open).

\Y\P\X302:Declare procedures needed by \\{make\_choices}\X\6
\4\&{procedure}\1\  \37$\\{make\_choices}(\\{knots},\39\\{coords}:%
\\{pointer})$;\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{found}$;\6
\4\&{var} \37\|h: \37\\{pointer};\C{the first breakpoint}\6
$\|p,\39\|q$: \37\\{pointer};\C{consecutive breakpoints being processed}\6
\X286:Local variables for \\{make\_choices}\X\2\6
\&{begin} \37\&{if} $\\{internal}[\\{tracing\_choices}]>0$ \1\&{then}\5
$\\{print\_path}(\\{knots},\39\.{",\ before\ choices"})$;\2\6
\\{check\_arith};\5
\X277:If consecutive knots are equal, join them explicitly\X;\6
\X278:Find the first breakpoint, \|h, on the path; insert an artificial
breakpoint if the path is an unbroken cycle\X;\6
$\|p\K\|h$;\6
\1\&{repeat} \37\X279:Fill in the control points between \|p and the next
breakpoint, then advance \|p to that breakpoint\X;\6
\4\&{until}\5
$\|p=\|h$;\2\6
\&{if} $\\{internal}[\\{tracing\_choices}]>0$ \1\&{then}\5
$\\{print\_path}(\\{knots},\39\.{",\ after\ choices"})$;\2\6
\&{while} $\\{coords}\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|p\K\\{coords}$;\5
$\\{coords}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{coord\_node\_size})$;\6
\&{end};\2\6
\&{if} $\\{arith\_error}$ \1\&{then}\5
\X276:Report an unexpected problem during the choice-making\X;\2\6
\&{end};\par
\fi

\M276. \P$\X276:Report an unexpected problem during the choice-making\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Some\ number\ got\ too\ big"})$;\5
$\\{help2}(\.{"The\ path\ that\ I\ just\ computed\ is\ out\ of\ range."})$\6
$(\.{"So\ it\ will\ probably\ look\ funny.\ Proceed,\ for\ a\ laugh."})$;\5
\\{error};\6
\&{end}\par
\U section~275.\fi

\M277. Two knots in a row with the same coordinates will always be joined
by an explicit ``curve'' whose control points are identical with the
knots.

\Y\P$\4\X277:If consecutive knots are equal, join them explicitly\X\S$\6
$\|p\K\\{knots}$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|p)$;\6
\&{if} $\\{x\_coord}(\|p)=\\{x\_coord}(\|q)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{y\_coord}(\|q)$ \1\&{then}\6
\&{if} $\\{right\_type}(\|p)>\\{explicit}$ \1\&{then}\6
\&{begin} \37$\\{right\_type}(\|p)\K\\{explicit}$;\6
\&{if} $\\{left\_type}(\|p)=\\{open}$ \1\&{then}\6
\&{begin} \37$\\{left\_type}(\|p)\K\\{curl}$;\5
$\\{left\_curl}(\|p)\K\\{unity}$;\6
\&{end};\2\6
$\\{left\_type}(\|q)\K\\{explicit}$;\6
\&{if} $\\{right\_type}(\|q)=\\{open}$ \1\&{then}\6
\&{begin} \37$\\{right\_type}(\|q)\K\\{curl}$;\5
$\\{right\_curl}(\|p)\K\\{unity}$;\6
\&{end};\2\6
$\\{right\_x}(\|p)\K\\{x\_coord}(\|p)$;\5
$\\{left\_x}(\|q)\K\\{x\_coord}(\|p)$;\5
$\\{right\_y}(\|p)\K\\{y\_coord}(\|p)$;\5
$\\{left\_y}(\|q)\K\\{y\_coord}(\|p)$;\6
\&{end};\2\2\2\6
$\|p\K\|q$;\6
\4\&{until}\5
$\|p=\\{knots}$\2\par
\U section~275.\fi

\M278. If there are no breakpoints, it is necessary to compute the direction
angles around an entire cycle. In this case the \\{left\_type} of the first
node is temporarily changed to \\{end\_cycle}.

\Y\P\D \37$\\{end\_cycle}=\\{open}+1$\par
\Y\P$\4\X278:Find the first breakpoint, \|h, on the path; insert an artificial
breakpoint if the path is an unbroken cycle\X\S$\6
$\|h\K\\{knots}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{left\_type}(\|h)\I\\{open}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\\{right\_type}(\|h)\I\\{open}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\|h\K\\{link}(\|h)$;\6
\&{if} $\|h=\\{knots}$ \1\&{then}\6
\&{begin} \37$\\{left\_type}(\|h)\K\\{end\_cycle}$;\5
\&{goto} \37\\{done1};\6
\&{end};\2\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~275.\fi

\M279. \P$\X279:Fill in the control points between \|p and the next breakpoint,
then advance \|p to that breakpoint\X\S$\6
$\|q\K\\{link}(\|p)$;\6
\&{if} $\\{right\_type}(\|p)\G\\{given}$ \1\&{then}\6
\&{begin} \37\&{while} $(\\{left\_type}(\|q)=\\{open})\W(\\{right\_type}(\|q)=%
\\{open})$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
\X284:Fill in the control information between consecutive breakpoints \|p and %
\|q\X;\6
\&{end};\2\6
$\|p\K\|q$\par
\U section~275.\fi

\M280. Before we can go further into the way choices are made, we need to
consider the underlying theory. The basic ideas implemented in \\{make%
\_choices}
are due to John Hobby, who introduced the notion of ``mock curvature''
at a knot. Angles are chosen so that they preserve mock curvature when
a knot is passed, and this has been found to produce excellent results.

\def\k{_{k+1}}
It is convenient to introduce some notations that simplify the necessary
formulas. Let $d_{k,k+1}=\vert z\k-z_k\vert$ be the (nonzero) distance
between knots \|k and $\|k+1$; and let
$${z\k-z_k\over z_k-z_{k-1}}={d_{k,k+1}\over d_{k-1,k}}e↑{i\psi_k}$$
so that a polygonal line from $z_{k-1}$ to $z_k$ to $z\k$ turns left
through an angle of~$\psi_k$. We assume that $\vert\psi_k\L180↑\circ$.
The control points for the spline from $z_k$ to $z\k$ will be denoted by
$$\eqalign{z_k↑+&=z_k+
\textstyle{1\over3}\rho_k e↑{i\theta_k}(z\k-z_k),\cr
z\k↑-&=z\k-
\textstyle{1\over3}\sigma\k e↑{-i\phi\k}(z\k-z_k),\cr}$$
where $\rho_k$ and $\sigma\k$ are nonnegative ``velocity ratios'' at the
beginning and end of the curve, while $\theta_k$ and $\phi\k$ are the
corresponding ``offset angles.'' These angles satisfy the condition
$$\theta_k+\phi_k+\psi_k=0,\eqno(*)$$
whenever the curve leaves an intermediate knot~\|k in the direction that
it enters.

\fi

\M281. Let $\alpha_k$ and $\beta\k$ be the reciprocals of the ``tension'' of
the curve at its beginning and ending points. This means that
$\rho_k=\alpha_k f(\theta_k,\phi\k)$ and $\sigma\k=\beta\k f(\phi\k,\theta_k)$,
where $f(\theta,\phi)$ is \MF's standard velocity function defined in
the \\{velocity} subroutine. The cubic spline $B(z_k,z_k↑+,z\k↑-,z\k;t)$
has curvature
$${2\sigma\k\sin(\theta_k+\phi\k)-6\sin\theta_k\over\rho_k↑2d_{k,k+1}}
\qquad{\rm and}\qquad
{2\rho_k\sin(\theta_k+\phi\k)-6\sin\phi\k\over\sigma\k↑2d_{k,k+1}}$$
at $\|t=0$ and $\|t=1$, respectively. The mock curvature is the linear
approximation to this true curvature that arises in the limit for
small $\theta_k$ and~$\phi\k$, if second-order terms are discarded.
The standard velocity function satisfies
$$f(\theta,\phi)=1+O(\theta↑2+\theta\phi+\phi↑2);$$
hence the mock curvatures are respectively
$${2\beta\k(\theta_k+\phi\k)-6\theta_k\over\alpha_k↑2d_{k,k+1}}
\qquad{\rm and}\qquad
{2\alpha_k(\theta_k+\phi\k)-6\phi\k\over\beta_k↑2d_{k,k+1}}.\eqno(**)$$

\fi

\M282. The turning angles $\psi_k$ are given, and equation $(*)$ above
determines $\phi_k$ when $\theta_k$ is known, so the task of
angle selection is essentially to choose appropriate values for each
$\theta_k$. When equation~$(*)$ is used to eliminate $\phi$~variables
from $(**)$, we obtain a system of linear equations of the form
$$A_k\theta_{k-1}+(B_k+C_k)\theta_k+D_k\theta\k=-B_k\psi_k-D_k\psi\k,$$
where
$$A_k={\alpha_{k-1}\over\beta_k↑2d_{k-1,k}},
\qquad B_k={3-\alpha_{k-1}\over\beta_k↑2d_{k-1,k}},
\qquad C_k={3-\beta\k\over\alpha_k↑2d_{k,k+1}},
\qquad D_k={\beta\k\over\alpha_k↑2d_{k,k+1}}.$$
The tensions are always $3\over4$ or more, hence each $\alpha$ and~$\beta$
will be at most $4\over3$. It follows that $B_k\G{5\over4}A_k$ and
$C_k\G{5\over4}D_k$; i.e., the equations are diagonally dominant;
hence they have a unique solution. Moreover, in most cases the tensions
are equal to~1, so that $B_k=2A_k$ and $C_k=2D_k$. This makes the
solution numerically stable, and there is an exponential damping
effect: The data at knot $k\pm j$ affects the angle at knot~$k$ by
a factor of~$O(2↑{-j})$.

\fi

\M283. However, we still must consider the angles at the starting and ending
knots of a non-cyclic path. These angles might be given explicitly, or
they might be specified implicitly in terms of an amount of ``curl.''

Let's assume that angles need to be determined for a non-cyclic path
starting at $z_0$ and ending at~$z_n$. Then equations of the form
$$A_k\theta_{k-1}+(B_k+C_k)\theta_k+D_k\theta_{k+1}=R_k$$
have been given for $0<k<n$, and it will be convenient to introduce
equations of the same form for $k=0$ and $k=n$, where
$$A_0=B_0=C_n=D_n=0.$$
If $\theta_0$ is supposed to have a given value $E_0$, we simply
define $C_0=0$, $D_0=0$, and $R_0=E_0$. Otherwise a curl
parameter, $\gamma_0$, has been specified at~$z_0$; this means
that the mock curvature at $z_0$ should be $\gamma_0$ times the
mock curvatue at $z_1$; i.e.,
$${2\beta_1(\theta_0+\phi_1)-6\theta_0\over\alpha_0↑2d_{01}}
=\gamma_0{2\alpha_0(\theta_0+\phi_1)-6\phi_1\over\beta_1↑2d_{01}}.$$
This equation simplifies to
$$(\alpha_0\chi_0+3-\beta_1)\theta_0+
\bigl((3-\alpha_0)\chi_0+\beta_1\bigr)\theta_1=
-\bigl((3-\alpha_0)\chi_0+\beta_1\bigr)\psi_1,$$
where $\chi_0=\alpha_0↑2\gamma_0/\beta_1↑2$; so we can set $C_0=
3-\beta_1+\chi_0\alpha_0$, $D_0=(3-\alpha_0)\chi_0+\beta_1$, $R_0=-D_0\psi_1$.
It can be shown that $C_0>0$ and $C_0B_1-A_1D_0>0$ when $\gamma_0\G0$,
hence the linear equations remain nonsingular.

Similar considerations apply at the right end, when the final angle $\phi_n$
may or may not need to be determined. It is convenient to let $\psi_n=0$,
hence $\theta_n=-\phi_n$. We either have an explicit equation $\theta_n=E_n$,
or we have
$$\bigl((3-\beta_n)\chi_n+\alpha_{n-1}\bigr)\theta_{n-1}+
(\beta_n\chi_n+3-\alpha_{n-1})\theta_n=0,\qquad
\chi_n={\beta_n↑2\gamma_n\over\alpha_{n-1}↑2}.$$

When \\{make\_choices} chooses angles, it must compute the coefficients of
these linear equations, then solve the equations. To compute the coefficients,
it is necessary to compute arctangents of the given turning angles~$\psi_k$.
When the equations are solved, the chosen directions $\theta_k$ are put
back into the form of control points by essentially computing sines and
cosines.

\fi

\M284. OK, we are ready to make the hard choices of \\{make\_choices}.

\Y\P$\4\X284:Fill in the control information between consecutive breakpoints %
\|p and \|q\X\S$\6
\X287:Calculate the turning angles $\psi_k$ and the distances $d_{k,k+1}$; set
$n$ to the length of the path\X;\6
\X288:Remove \\{open} types at the breakpoints\X;\6
\X290:Solve linear equations and fill in the control information between
breakpoints \|p and~\|q, unless a simple case makes the calculations
unnecessary\X\par
\U section~279.\fi

\M285. It's convenient to precompute quantities that will be needed several
times later. The values of $\\{delta\_x}[\|k]$ and $\\{delta\_y}[\|k]$ will be
the
coordinates of $z\k-z_k$, and the magnitude of this vector will be
$\\{delta}[\|k]=\hbox{$d_{k,k+1}$}$. The path angle $\psi_k$ between
$z_k-z_{k-1}$
and $z\k-z_k$ will be stored in $\\{psi}[\|k]$.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{delta\_x},\39\\{delta\_y},\39\\{delta}$: \37\&{array} $[0\to\\{path%
\_size}]$ \1\&{of}\5
\\{scaled};\C{knot differences}\2\6
\4\\{psi}: \37\&{array} $[1\to\\{path\_size}]$ \1\&{of}\5
\\{angle};\C{turning angles}\2\par
\fi

\M286. \P$\X286:Local variables for \\{make\_choices}\X\S$\6
\4$\|k,\39\|n$: \37$0\to\\{path\_size}$;\C{current and final knot numbers}\6
\4$\|r,\39\|s,\39\|t$: \37\\{pointer};\C{registers for list traversal}\6
\4$\\{sine},\39\\{cosine}$: \37\\{fraction};\C{trig functions of various
angles}\par
\A section~292.
\U section~275.\fi

\M287. \P$\X287:Calculate the turning angles $\psi_k$ and the distances
$d_{k,k+1}$; set $n$ to the length of the path\X\S$\6
$\|k\K0$;\5
$\|s\K\|p$;\5
$\|n\K\\{path\_size}$;\6
\1\&{repeat} \37$\|t\K\\{link}(\|s)$;\5
$\\{delta\_x}[\|k]\K\\{x\_coord}(\|t)-\\{x\_coord}(\|s)$;\5
$\\{delta\_y}[\|k]\K\\{y\_coord}(\|t)-\\{y\_coord}(\|s)$;\5
$\\{delta}[\|k]\K\\{pyth\_add}(\\{delta\_x}[\|k],\39\\{delta\_y}[\|k])$;\6
\&{if} $\|k>0$ \1\&{then}\6
\&{begin} \37$\\{sine}\K\\{make\_fraction}(\\{delta\_y}[\|k-1],\39\\{delta}[%
\|k-1])$;\5
$\\{cosine}\K\\{make\_fraction}(\\{delta\_x}[\|k-1],\39\\{delta}[\|k-1])$;\5
$\\{psi}[\|k]\K\\{m\_atan}(\\{take\_fraction}(\\{delta\_x}[\|k],\39\\{cosine})+%
\\{take\_fraction}(\\{delta\_y}[\|k],\39\\{sine}),\39\\{take\_fraction}(%
\\{delta\_y}[\|k],\39\\{cosine})-\\{take\_fraction}(\\{delta\_x}[\|k],\39%
\\{sine}))$;\6
\&{end};\2\6
$\\{incr}(\|k)$;\5
$\|s\K\|t$;\6
\&{if} $\|k=\\{path\_size}$ \1\&{then}\5
$\\{overflow}(\.{"path\ size"},\39\\{path\_size})$;\2\6
\&{if} $\|s=\|q$ \1\&{then}\5
$\|n\K\|k$;\2\6
\4\&{until}\5
$(\|k\G\|n)\W(\\{left\_type}(\|s)\I\\{end\_cycle})$;\2\6
\&{if} $\|k=\|n$ \1\&{then}\5
$\\{psi}[\|n]\K0$\2\par
\U section~284.\fi

\M288. When we get to this point of the code, $\\{right\_type}(\|p)$ is either
\\{given} or \\{curl} or \\{open}. If it is \\{open}, we must have
$\\{left\_type}(\|p)=\\{end\_cycle}$ or $\\{left\_type}(\|p)=\\{explicit}$. In
the latter
case, the \\{open} type is converted to \\{given}; however, if the
velocity coming in to this knot is zero, the \\{open} type is
converted to a \\{curl}, since we don't know the incoming direction.

Similarly, $\\{left\_type}(\|q)$ is either \\{given} or \\{curl} or \\{open} or
\\{end\_cycle}. The \\{open} possibility is reduced either to \\{given} or to %
\\{curl}.

\Y\P$\4\X288:Remove \\{open} types at the breakpoints\X\S$\6
\&{if} $\\{left\_type}(\|q)=\\{open}$ \1\&{then} \6
\&{begin} \37$\\{x\_coord}(\\{right\_delta})\K\\{right\_x}(\|q)-\\{x\_coord}(%
\|q)$;\5
$\\{y\_coord}(\\{right\_delta})\K\\{right\_y}(\|q)-\\{y\_coord}(\|q)$;\6
\&{if} $(\\{x\_coord}(\\{right\_delta})=0)\W(\\{y\_coord}(\\{right\_delta})=0)$
\1\&{then}\6
\&{begin} \37$\\{left\_type}(\|q)\K\\{curl}$;\5
$\\{left\_curl}(\|q)\K\\{unity}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{left\_type}(\|q)\K\\{given}$;\5
$\\{left\_given}(\|q)\K\\{right\_delta}$;\6
\&{end};\2\6
\&{if} $(\\{right\_type}(\|p)=\\{open})\W(\\{left\_type}(\|p)=\\{explicit})$ \1%
\&{then} \6
\&{begin} \37$\\{x\_coord}(\\{left\_delta})\K\\{x\_coord}(\|q)-\\{left\_x}(%
\|q)$;\5
$\\{y\_coord}(\\{left\_delta})\K\\{y\_coord}(\|q)-\\{left\_y}(\|q)$;\6
\&{if} $(\\{x\_coord}(\\{left\_delta})=0)\W(\\{y\_coord}(\\{left\_delta})=0)$ %
\1\&{then}\6
\&{begin} \37$\\{right\_type}(\|q)\K\\{curl}$;\5
$\\{right\_curl}(\|q)\K\\{unity}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{right\_type}(\|q)\K\\{given}$;\5
$\\{right\_given}(\|q)\K\\{left\_delta}$;\6
\&{end}\2\par
\U section~284.\fi

\M289. Linear equations need to be solved whenever $\|n>1$; and also when $%
\|n=1$
and exactly one of the breakpoints involves a curl. The simplest case occurs
when $\|n=1$ and there is a curl at both breakpoints; then we simply draw
a straight line.

But before coding up the simple cases, we might as well face the general case,
since we must deal with it sooner or later, and since the general case
is likely to give some insight into the way simple cases are handled best.

When there is no cycle, the linear equations to be solved form a tri-diagonal
system, and we can apply the standard technique of Gaussian elimination
to convert that system to a sequence of equations of the form
$$\theta_0+u_0\theta_1=v_0,\quad
\theta_1+u_1\theta_2=v_1,\quad\ldots,
\theta_{n-1}+u_{n-1}\theta_n=v_{n-1},\quad
\theta_n=v_n.$$
It is possible to do this diagonalization while generating the equations.
Once $\theta_n$ is known, it is easy to determine $\theta_{n-1}$, \dots,
$\theta_1$, $\theta_0$; thus, the equations will be solved.

The procedure is slightly more complex when there is a cycle, but the basic
idea will be nearly the same. In the right-hand sides will be $v_k+w_k\theta_0$
instead of simply $v_k$, and we will start the process off with $u_0=v_0=0$,
$w_0=1$. The final equation will be not $\theta_n=v_n$ but
$\theta_n+u_n\theta_1=v_n+w_n\theta_0$; an appropriate ending routine
will take account of the fact that $\theta_n=\theta_0$ and eliminate
the $w$'s from the system, after which the solution can be obtained
as before.

When $u_k$, $v_k$, and $w_k$ are being computed, the three pointer
variables \|r, \|s,~\|t will point respectively to knots $\|k-1$, \|k,
and~$\|k+1$. The $u$'s and $w$'s are scaled by $2↑{28}$, i.e., they are
of type \\{fraction}; the $\theta$'s and $v$'s are of type \\{angle}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{theta}: \37\&{array} $[0\to\\{path\_size}]$ \1\&{of}\5
\\{angle};\C{values of $\theta_k$}\2\6
\4\\{uu}: \37\&{array} $[0\to\\{path\_size}]$ \1\&{of}\5
\\{fraction};\C{values of $u_k$}\2\6
\4\\{vv}: \37\&{array} $[0\to\\{path\_size}]$ \1\&{of}\5
\\{angle};\C{values of $v_k$}\2\6
\4\\{ww}: \37\&{array} $[0\to\\{path\_size}]$ \1\&{of}\5
\\{fraction};\C{values of $w_k$}\2\par
\fi

\M290. Our immediate problem is to get the ball rolling by setting up the
first equation or by realizing that no equations are needed, and to fit
this initialization into a framework suitable for the overall computation.

\Y\P$\4\X290:Solve linear equations and fill in the control information between
breakpoints \|p and~\|q, unless a simple case makes the calculations
unnecessary\X\S$\6
$\|k\K0$;\5
$\|s\K\|p$;\6
\~ \1\&{loop}\ \&{begin} \37$\|t\K\\{link}(\|s)$;\6
\&{if} $\|k=0$ \1\&{then}\5
\X291:Get the linear equations started; or \&{goto} \\{done} with the control
points in place, if linear equations needn't be solved\X\6
\4\&{else} \&{case} $\\{left\_type}(\|s)$ \1\&{of}\6
\4$\\{end\_cycle},\39\\{open}$: \37\X293:Set up equation to match mock
curvatures at $z_k$; then \&{goto} \\{found} with $\theta_n$ adjusted to equal
$\theta_0$, if a cycle has ended\X;\6
\4\\{curl}: \37\X301:Set up equation for a curl at $\theta_n$ and \&{goto} %
\\{found}\X;\6
\4\\{given}: \37\X298:Calculate the given value of $\theta_n$ and \&{goto} %
\\{found}\X;\2\6
\&{end};\C{there are no other cases}\2\6
$\|r\K\|s$;\5
$\|s\K\|t$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\4\\{found}: \37\X303:Finish choosing angles and assigning control points\X;\6
\4\\{done}: \37\par
\U section~284.\fi

\M291. On the first time through the loop, we have $\|k=0$ and \|r is not yet
defined. The first linear equation, if any, will have $A_0=B_0=0$.

\Y\P$\4\X291:Get the linear equations started; or \&{goto} \\{done} with the
control points in place, if linear equations needn't be solved\X\S$\6
\&{case} $\\{right\_type}(\|s)$ \1\&{of}\6
\4\\{given}: \37\&{if} $\\{left\_type}(\|t)=\\{given}$ \1\&{then}\5
\X306:Reduce to simple case of two givens and \&{goto} \\{done}\X\6
\4\&{else} \X299:Set up the equation for a given value of $\theta_0$\X;\2\6
\4\\{curl}: \37\&{if} $\\{left\_type}(\|t)=\\{curl}$ \1\&{then}\5
\X307:Reduce to simple case of straight line and \&{goto} \\{done}\X\6
\4\&{else} \X300:Set up the equation for a curl at $\theta_0$\X;\2\6
\4\\{open}: \37\&{begin} \37$\\{uu}[0]\K0$;\5
$\\{vv}[0]\K0$;\5
$\\{ww}[0]\K\\{fraction\_one}$;\6
\&{end};\C{this begins a cycle}\2\6
\&{end}\C{there are no other cases}\par
\U section~290.\fi

\M292. The general equation that specifies equality of mock curvature at $z_k$
is
$$A_k\theta_{k-1}+(B_k+C_k)\theta_k+D_k\theta\k=-B_k\psi_k-D_k\psi\k,$$
as derived above. We want to combine this with the already-derived equation
$\theta_{k-1}+u_{k-1}\theta_k=v_{k-1}+w_{k-1}\theta_0$ in order to obtain
a new equation
$\theta_k+u_k\theta\k=v_k+w_k\theta_0$. This can be done by dividing the
equation
$$(B_k-u_{k-1}A_k+C_k)\theta_k+D_k\theta\k=-B_k\psi_k-D_k\psi\k-A_kv_{k-1}
-A_kw_{k-1}\theta_0$$
by $B_k-u_{k-1}A_k+C_k$. The trick is to do this carefully with
fixed-point arithmetic, avoiding the chance of overflow while retaining
suitable precision.

The calculations will be performed in several registers that
provide temporary storage for intermediate quantities.

\Y\P$\4\X286:Local variables for \\{make\_choices}\X\mathrel{+}\S$\6
\4$\\{aa},\39\\{bb},\39\\{cc},\39\\{ff},\39\\{acc}$: \37\\{fraction};%
\C{temporary registers}\6
\4$\\{dd},\39\\{ee}$: \37\\{scaled};\C{likewise, but \\{scaled}}\par
\fi

\M293. \P$\X293:Set up equation to match mock curvatures at $z_k$; then %
\&{goto} \\{found} with $\theta_n$ adjusted to equal $\theta_0$, if a cycle has
ended\X\S$\6
\&{begin} \37\X294:Calculate the values $\\{aa}=A_k/B_k$, $\\{bb}=D_k/C_k$, $%
\\{dd}=(3-\alpha_{k-1})d_{k,k+1}$, $\\{ee}=(3-\beta\k)d_{k-1,k}$, and $%
\\{cc}=(B_k-u_{k-1}A_k)/B_k$\X;\6
\X295:Calculate the ratio $\\{ff}=C_k/(C_k+B_k-u_{k-1}A_k)$\X;\6
$\\{uu}[\|k]\K\\{take\_fraction}(\\{ff},\39\\{bb})$;\5
\X296:Calculate the values of $v_k$ and $w_k$\X;\6
\&{if} $\\{left\_type}(\|s)=\\{end\_cycle}$ \1\&{then}\5
\X297:Adjust $\theta_n$ to equal $\theta_0$ and \&{goto} \\{found}\X;\2\6
\&{end}\par
\U section~290.\fi

\M294. Since tension values are never less than 3/4, the values \\{aa} and
\\{bb} computed here are never more than 4/5.

\Y\P$\4\X294:Calculate the values $\\{aa}=A_k/B_k$, $\\{bb}=D_k/C_k$, $%
\\{dd}=(3-\alpha_{k-1})d_{k,k+1}$, $\\{ee}=(3-\beta\k)d_{k-1,k}$, and $%
\\{cc}=(B_k-u_{k-1}A_k)/B_k$\X\S$\6
\&{if} $\\{right\_tension}(\|r)=\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{aa}\K\\{fraction\_half}$;\5
$\\{dd}\K2\ast\\{delta}[\|k]$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{aa}\K\\{make\_fraction}(\\{unity},\393\ast\\{right%
\_tension}(\|r)-\\{unity})$;\5
$\\{dd}\K\\{take\_fraction}(\\{delta}[\|k],\39\\{fraction\_three}-\\{make%
\_fraction}(\\{unity},\39\\{right\_tension}(\|r)))$;\6
\&{end};\2\6
\&{if} $\\{left\_tension}(\|t)=\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{bb}\K\\{fraction\_half}$;\5
$\\{ee}\K2\ast\\{delta}[\|k-1]$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{bb}\K\\{make\_fraction}(\\{unity},\393\ast\\{left%
\_tension}(\|t)-\\{unity})$;\5
$\\{ee}\K\\{take\_fraction}(\\{delta}[\|k-1],\39\\{fraction\_three}-\\{make%
\_fraction}(\\{unity},\39\\{left\_tension}(\|t)))$;\6
\&{end};\2\6
$\\{cc}\K\\{fraction\_one}-\\{take\_fraction}(\\{uu}[\|k-1],\39\\{aa})$\par
\U section~293.\fi

\M295. The ratio to be calculated in this step can be written in the form
$$\beta_k↑2\cdot\\{ee}\over\beta_k↑2\cdot\\{ee}+\alpha_k↑2\cdot\\{cc}\\{dd},$$
because of the quantities just calculated. The values of \\{dd} and \\{ee}
will not be needed after this step has been performed.

\Y\P$\4\X295:Calculate the ratio $\\{ff}=C_k/(C_k+B_k-u_{k-1}A_k)$\X\S$\6
$\\{dd}\K\\{take\_fraction}(\\{dd},\39\\{cc})$;\6
\&{if} $\\{left\_tension}(\|s)\I\\{right\_tension}(\|s)$ \1\&{then}\C{$%
\beta_k↑{-1}≠\alpha_k↑{-1}$}\6
\&{if} $\\{left\_tension}(\|s)<\\{right\_tension}(\|s)$ \1\&{then}\6
\&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{left\_tension}(\|s),\39\\{right%
\_tension}(\|s))$;\5
$\\{ff}\K\\{take\_fraction}(\\{ff},\39\\{ff})$;\C{$\alpha_k↑2/\beta_k↑2$}\6
$\\{dd}\K\\{take\_fraction}(\\{dd},\39\\{ff})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{right\_tension}(\|s),\39%
\\{left\_tension}(\|s))$;\5
$\\{ff}\K\\{take\_fraction}(\\{ff},\39\\{ff})$;\C{$\beta_k↑2/\alpha_k↑2$}\6
$\\{ee}\K\\{take\_fraction}(\\{ee},\39\\{ff})$;\6
\&{end};\2\2\6
$\\{ff}\K\\{make\_fraction}(\\{ee},\39\\{ee}+\\{dd})$\par
\U section~293.\fi

\M296. The value of $u_[k-1]$ will be $\L1$ except when $k=1$ and the previous
equation was specified by a curl. In that case we must use a special
method of computation to prevent overflow.

Fortunately, the calculations turn out to be even simpler in this ``hard''
case. The curl equation makes $w_0=0$ and $v_0=-u_0\psi_1$, hence
$-B_1\psi_1-A_1v_0=-(B_1-u_0A_1)\psi_1=-\\{cc}\cdot B_1\psi_1$.

\Y\P$\4\X296:Calculate the values of $v_k$ and $w_k$\X\S$\6
$\\{acc}\K-\\{take\_fraction}(\\{psi}[\|k+1],\39\\{uu}[\|k])$;\6
\&{if} $\\{right\_type}(\|r)=\\{curl}$ \1\&{then}\6
\&{begin} \37$\\{ww}[\|k]\K0$;\5
$\\{vv}[\|k]\K\\{acc}-\\{take\_fraction}(\\{psi}[1],\39\\{fraction\_one}-%
\\{ff})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{fraction\_one}-\\{ff},%
\39\\{cc})$;\C{this is 		$B_k/(C_k+B_k-u_{k-1}A_k)<5$}\6
$\\{acc}\K\\{acc}-\\{take\_fraction}(\\{psi}[\|k],\39\\{ff})$;\5
$\\{ff}\K\\{take\_fraction}(\\{ff},\39\\{aa})$;\C{this is
$A_k/(C_k+B_k-u_{k-1}A_k)$}\6
$\\{vv}[\|k]\K\\{acc}-\\{take\_fraction}(\\{vv}[\|k-1],\39\\{ff})$;\6
\&{if} $\\{ww}[\|k-1]=0$ \1\&{then}\5
$\\{ww}[\|k]\K0$\6
\4\&{else} $\\{ww}[\|k]\K-\\{take\_fraction}(\\{ww}[\|k-1],\39\\{ff})$;\2\6
\&{end}\2\par
\U section~293.\fi

\M297. When a complete cycle has been traversed, we have $\theta_k+u_k\theta\k=
v_k+w_k\theta_0$, for $1\L\|k\L\|n$. We would like to determine the value of
$\theta_n$ ad reduce the system to the form $\theta_k+u_k\theta\k=v_k$
for $0\L\|k<\|n$, so that the cyclic case can be finished up just as if there
were no cycle.

The idea in the following code is to observe that
$$\eqalign{\theta_n&=v_n+w_n\theta_0-u_n\theta_1=\cdots\cr
&=v_n+w_n\theta_0-u_n\bigl(v_1+w_1\theta_0-u_1(v_2+\cdots
-u_{n-2}(v_{n-1}+w_{n-1}\theta_0-u_{n-1}\theta_0))\bigr),\cr}$$
so we can solve for $\theta_n=\theta_0$.

\Y\P$\4\X297:Adjust $\theta_n$ to equal $\theta_0$ and \&{goto} \\{found}\X\S$\6
\&{begin} \37$\\{aa}\K0$;\5
$\\{bb}\K\\{fraction\_one}$;\C{we have $\|k=\|n$}\6
\1\&{repeat} \37$\\{decr}(\|k)$;\6
\&{if} $\|k=0$ \1\&{then}\5
$\|k\K\|n$;\2\6
$\\{aa}\K\\{vv}[\|k]-\\{take\_fraction}(\\{aa},\39\\{uu}[\|k])$;\5
$\\{bb}\K\\{ww}[\|k]-\\{take\_fraction}(\\{bb},\39\\{uu}[\|k])$;\6
\4\&{until}\5
$\|k=\|n$;\2\6
$\\{aa}\K\\{make\_fraction}(\\{aa},\39\\{fraction\_one}-\\{bb})$;\5
$\\{theta}[\|n]\K\\{aa}$;\5
$\\{vv}[0]\K\\{aa}$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\|n-1$ \1\&{do}\5
$\\{vv}[\|k]\K\\{vv}[\|k]+\\{take\_fraction}(\\{aa},\39\\{ww}[\|k])$;\2\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~293.\fi

\M298. \P$\X298:Calculate the given value of $\theta_n$ and \&{goto} \\{found}%
\X\S$\6
\&{begin} \37$\|r\K\\{left\_given}(\|s)$;\6
$\\{sine}\K\\{make\_fraction}(\\{delta\_y}[\|n-1],\39\\{delta}[\|n-1])$;\5
$\\{cosine}\K\\{make\_fraction}(\\{delta\_x}[\|n-1],\39\\{delta}[\|n-1])$;\6
$\\{theta}[\|n]\K\\{n\_atan}(\\{take\_fraction}(\\{x\_coord}(\|r),\39%
\\{cosine})+\\{take\_fraction}(\\{y\_coord}(\|r),\39\\{sine}),\39\30\\{take%
\_fraction}(\\{y\_coord}(\|r),\39\\{cosine})-\\{take\_fraction}(\\{x\_coord}(%
\|r),\39\\{sine}))$;\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~290.\fi

\M299. \P$\X299:Set up the equation for a given value of $\theta_0$\X\S$\6
\&{begin} \37$\|r\K\\{right\_given}(\|s)$;\6
$\\{sine}\K\\{make\_fraction}(\\{delta\_y}[0],\39\\{delta}[0])$;\5
$\\{cosine}\K\\{make\_fraction}(\\{delta\_x}[0],\39\\{delta}[0])$;\6
$\\{vv}[0]\K\\{n\_atan}(\\{take\_fraction}(\\{x\_coord}(\|r),\39\\{cosine})+%
\\{take\_fraction}(\\{y\_coord}(\|r),\39\\{sine}),\39\30\\{take\_fraction}(\|y,%
\39\\{coord}(\|r),\39\\{cosine})-\\{take\_fraction}(\\{x\_coord}(\|r),\39%
\\{sine}))$;\5
$\\{uu}[0]\K0$;\5
$\\{ww}[0]\K0$;\6
\&{end}\par
\U section~291.\fi

\M300. \P$\X300:Set up the equation for a curl at $\theta_0$\X\S$\6
\&{begin} \37$\\{cc}\K\\{right\_curl}(\|s)$;\6
\&{if} $(\\{right\_tension}(\|s)=\\{unity})\W(\\{left\_tension}(\|t)=%
\\{unity})$ \1\&{then}\5
$\\{uu}[0]\K\\{make\_fraction}(\\{cc}+\\{cc}+\\{unity},\39\\{cc}+\\{two})$\6
\4\&{else} $\\{uu}[0]\K\\{curl\_ratio}(\\{cc},\39\\{right\_tension}(\|s),\39%
\\{left\_tension}(\|t))$;\2\6
$\\{vv}[0]\K-\\{take\_fraction}(\\{psi}[1],\39\\{uu}[0])$;\5
$\\{ww}[0]\K0$;\6
\&{end}\par
\U section~291.\fi

\M301. \P$\X301:Set up equation for a curl at $\theta_n$ and \&{goto} \\{found}%
\X\S$\6
\&{begin} \37$\\{cc}\K\\{left\_curl}(\|s)$;\6
\&{if} $(\\{right\_tension}(\|r)=\\{unity})\W(\\{left\_tension}(\|s)=%
\\{unity})$ \1\&{then}\5
$\\{ff}\K\\{make\_fraction}(\\{cc}+\\{cc}+\\{unity},\39\\{cc}+\\{two})$\6
\4\&{else} $\\{ff}\K\\{curl\_ratio}(\\{cc},\39\\{left\_tension}(\|s),\39%
\\{right\_tension}(\|r))$;\2\6
$\\{theta}[\|n]\K-\\{make\_fraction}(\\{take\_fraction}(\\{vv}[\|n-1],\39%
\\{ff}),\39\\{fraction\_one}-\\{take\_fraction}(\\{ff},\39\\{uu}[\|n-1]))$;\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~290.\fi

\M302. The \\{curl\_ratio} subroutine has three arguments, which our previous
notation
encourages us to call $\gamma$, $\alpha↑{-1}$, and $\beta↑{-1}$. It is
a somewhat tedious program to calculate
$${(3-\alpha)\alpha↑2\gamma+\beta↑3\over
\alpha↑3\gamma+(3-\beta)\beta↑2},$$
with the result reduced to 4 if it exceeds 4. (This reduction of curl
is necessary only if the curl and tension are both large.)
The values of $\alpha$ and $\beta$ will be at most~4/3.

\Y\P$\4\X302:Declare procedures needed by \\{make\_choices}\X\S$\6
\4\&{function}\1\  \37$\\{curl\_ratio}(\\{gamma},\39\\{a\_tension},\39\\{b%
\_tension}:\\{scaled})$: \37\\{fraction};\6
\4\&{var} \37$\\{alpha},\39\\{beta},\39\\{num},\39\\{denom},\39\\{ff}$: \37%
\\{fraction};\C{registers}\2\6
\&{begin} \37$\\{alpha}\K\\{make\_fraction}(\\{unity},\39\\{a\_tension})$;\5
$\\{beta}\K\\{make\_fraction}(\\{unity},\39\\{b\_tension})$;\6
\&{if} $\\{alpha}\L\\{beta}$ \1\&{then}\6
\&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{alpha},\39\\{beta})$;\5
$\\{ff}\K\\{take\_fraction}(\\{ff},\39\\{ff})$;\5
$\\{gamma}\K\\{take\_fraction}(\\{gamma},\39\\{ff})$;\6
$\\{beta}\K\\{beta}\mathbin{\&{div}}\O{10000}$;\C{convert \\{fraction} to %
\\{scaled}}\6
$\\{denom}\K\\{take\_fraction}(\\{gamma},\39\\{alpha})+\\{three}-\\{beta}$;\5
$\\{num}\K\\{take\_fraction}(\\{gamma},\39\\{fraction\_three}-\\{alpha})+%
\\{beta}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{beta},\39\\{alpha})$;\5
$\\{ff}\K\\{take\_fraction}(\\{ff},\39\\{ff})$;\5
$\\{beta}\K\\{take\_fraction}(\\{beta},\39\\{ff})\mathbin{\&{div}}\O{10000}$;%
\C{convert \\{fraction} to \\{scaled}}\6
$\\{denom}\K\\{take\_fraction}(\\{gamma},\39\\{alpha})+(\\{ff}\mathbin{%
\&{div}}1365)-\\{beta}$;\C{$1365\approx 2↑{12}/3$}\6
$\\{num}\K\\{take\_fraction}(\\{gamma},\39\\{fraction\_three}-\\{alpha})+%
\\{beta}$;\6
\&{end};\2\6
\&{if} $\\{num}\G\\{denom}+\\{denom}+\\{denom}+\\{denom}$ \1\&{then}\5
$\\{curl\_ratio}\K\\{fraction\_four}$\6
\4\&{else} $\\{curl\_ratio}\K\\{make\_fraction}(\\{num},\39\\{denom})$;\2\6
\&{end};\par
\A section~305.
\U section~275.\fi

\M303. We're in the home stretch now.

\Y\P$\4\X303:Finish choosing angles and assigning control points\X\S$\6
\&{for} $\|k\K\|n-1\mathrel{\&{downto}}0$ \1\&{do}\5
$\\{theta}[\|k]\K\\{vv}[\|k]-\\{take\_fraction}(\\{theta}[\|k+1],\39\\{uu}[%
\|k])$;\2\6
$\|s\K\|p$;\5
$\|k\K0$;\6
\1\&{repeat} \37$\|t\K\\{link}(\|s)$;\6
$\\{n\_sin\_cos}(\\{theta}[\|k])$;\5
$\\{st}\K\\{n\_sin}$;\5
$\\{ct}\K\\{n\_cos}$;\6
$\\{n\_sin\_cos}(-\\{psi}[\|k+1]-\\{theta}[\|k+1])$;\5
$\\{sf}\K\\{n\_sin}$;\5
$\\{cf}\K\\{n\_cos}$;\6
$\\{set\_controls}(\|s,\39\|t,\39\|k)$;\6
$\\{incr}(\|k)$;\5
$\|s\K\|t$;\6
\4\&{until}\5
$\|k=\|n$\2\par
\U section~290.\fi

\M304. The \\{set\_controls} routine actually puts the control points into
a pair of consecutive nodes \|p and~\|q. Global variables are used to
record the values of $\sin\theta$, $\cos\theta$, $\sin\phi$, and
$\cos\phi$ needed in this calculation.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{st},\39\\{ct},\39\\{sf},\39\\{cf}$: \37\\{fraction};\C{sines and cosines}%
\par
\fi

\M305. \P$\X302:Declare procedures needed by \\{make\_choices}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{set\_controls}(\|p,\39\|q:\\{pointer};\,\35\|k:%
\\{integer})$;\6
\4\&{var} \37$\\{rr},\39\\{ss}$: \37\\{fraction};\C{velocities, divided by
thrice the tension}\2\6
\&{begin} \37$\\{rr}\K\\{velocity}(\\{st},\39\\{ct},\39\\{sf},\39\\{cf},\39%
\\{right\_tension}(\|p))$;\5
$\\{ss}\K\\{velocity}(\\{sf},\39\\{cf},\39\\{st},\39\\{ct},\39\\{left%
\_tension}(\|q))$;\5
$\\{right\_x}(\|p)\K\\{x\_coord}(\|p)+\\{take\_fraction}(\\{take\_fraction}(%
\\{delta\_x}[\|k],\39\\{ct})-\\{take\_fraction}(\\{delta\_y}[\|k],\39\\{st}),%
\39\\{rr})$;\5
$\\{right\_y}(\|p)\K\\{y\_coord}(\|p)+\\{take\_fraction}(\\{take\_fraction}(%
\\{delta\_y}[\|k],\39\\{ct})+\\{take\_fraction}(\\{delta\_x}[\|k],\39\\{st}),%
\39\\{rr})$;\5
$\\{left\_x}(\|q)\K\\{x\_coord}(\|q)-\\{take\_fraction}(\\{take\_fraction}(%
\\{delta\_x}[\|k],\39\\{cf})+\\{take\_fraction}(\\{delta\_y}[\|k],\39\\{sf}),%
\39\\{ss})$;\5
$\\{right\_y}(\|q)\K\\{y\_coord}(\|q)-\\{take\_fraction}(\\{take\_fraction}(%
\\{delta\_y}[\|k],\39\\{cf})-\\{take\_fraction}(\\{delta\_x}[\|k],\39\\{sf}),%
\39\\{ss})$;\5
$\\{right\_type}(\|p)\K\\{explicit}$;\5
$\\{left\_type}(\|q)\K\\{explicit}$;\6
\&{end};\par
\fi

\M306. Only the simple cases remain to be handled.

\Y\P$\4\X306:Reduce to simple case of two givens and \&{goto} \\{done}\X\S$\6
\&{begin} \37$\\{cosine}\K\\{make\_fraction}(\\{delta\_x}[0],\39\\{delta}[0])$;%
\5
$\\{sine}\K\\{make\_fraction}(\\{delta\_y}[0],\39\\{delta}[0])$;\5
$\|r\K\\{right\_given}(\|p)$;\6
$\\{ct}\K\\{take\_fraction}(\\{x\_coord}(\|r),\39\\{cosine})+\\{take%
\_fraction}(\\{y\_coord}(\|r),\39\\{sine})$;\5
$\\{st}\K\\{take\_fraction}(\\{y\_coord}(\|r),\39\\{cosine})-\\{take%
\_fraction}(\\{x\_coord}(\|r),\39\\{sine})$;\6
$\\{aa}\K\\{pyth\_add}(\\{st},\39\\{ct})$;\5
$\\{ct}\K\\{take\_fraction}(\\{ct},\39\\{aa})$;\5
$\\{st}\K\\{take\_fraction}(\\{st},\39\\{aa})$;\6
$\|r\K\\{left\_given}(\|q)$;\6
$\\{cf}\K\\{take\_fraction}(\\{x\_coord}(\|r),\39\\{cosine})+\\{take%
\_fraction}(\\{y\_coord}(\|r),\39\\{sine})$;\5
$\\{sf}\K-\\{take\_fraction}(\\{y\_coord}(\|r),\39\\{cosine})+\\{take%
\_fraction}(\\{x\_coord}(\|r),\39\\{sine})$;\6
$\\{aa}\K\\{pyth\_add}(\\{sf},\39\\{cf})$;\5
$\\{cf}\K\\{take\_fraction}(\\{cf},\39\\{aa})$;\5
$\\{sf}\K\\{take\_fraction}(\\{sf},\39\\{aa})$;\6
$\\{set\_controls}(\|p,\39\|q,\390)$;\5
\&{goto} \37\\{done};\6
\&{end}\par
\U section~291.\fi

\M307. \P$\X307:Reduce to simple case of straight line and \&{goto} \\{done}\X%
\S$\6
\&{begin} \37$\\{right\_type}(\|p)\K\\{explicit}$;\5
$\\{left\_type}(\|q)\K\\{explicit}$;\6
\&{if} $\\{right\_tension}(\|p)=\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{right\_x}(\|p)\K\\{x\_coord}(\|p)+((\\{delta\_x}[0]+1)%
\mathbin{\&{div}}3)$;\5
$\\{right\_y}(\|p)\K\\{y\_coord}(\|p)+((\\{delta\_y}[0]+1)\mathbin{\&{div}}3)$;%
\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{unity},\393\ast\\{right%
\_tension}(\|p))$;\C{$\alpha/3$}\6
$\\{right\_x}(\|p)\K\\{x\_coord}(\|p)+\\{take\_fraction}(\\{delta\_x}[0],\39%
\\{ff})$;\5
$\\{right\_y}(\|p)\K\\{y\_coord}(\|p)+\\{take\_fraction}(\\{delta\_y}[0],\39%
\\{ff})$;\6
\&{end};\2\6
\&{if} $\\{left\_tension}(\|q)=\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{left\_x}(\|q)\K\\{x\_coord}(\|q)-((\\{delta\_x}[0]+1)\mathbin{%
\&{div}}3)$;\5
$\\{left\_y}(\|q)\K\\{y\_coord}(\|q)-((\\{delta\_y}[0]+1)\mathbin{\&{div}}3)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{ff}\K\\{make\_fraction}(\\{unity},\393\ast\\{left%
\_tension}(\|q))$;\C{$\beta/3$}\6
$\\{left\_x}(\|q)\K\\{x\_coord}(\|q)-\\{take\_fraction}(\\{delta\_x}[0],\39%
\\{ff})$;\5
$\\{left\_y}(\|q)\K\\{y\_coord}(\|q)-\\{take\_fraction}(\\{delta\_y}[0],\39%
\\{ff})$;\6
\&{end};\2\6
\&{goto} \37\\{done};\6
\&{end}\par
\U section~291.\fi

\N308.  \[xx] Generating discrete moves.
The purpose of the next part of \MF\ is to compute discrete approximations
to curves described as parametric polynomial functions $z(t)$.
We shall start with the low level first, because an efficient ``engine''
is needed to support the high-level constructions.

Most of the subroutines are based on variations of a single theme,
namely the idea of {\sl bisection}. Given a Bernshte{\u\i}n polynomial
$$B(z_0,z_1,\ldots,z_n;t)=\sum_k{n\choose k}t↑k(1-t)↑{n-k}z_k,$$
we can conveniently bisect its range as follows:

\smallskip
\textindent{1)} Let $z_k↑{(0)}=z_k$, for $0\L\|k\L\|n$.

\smallskip
\textindent{2)} Let $z_k↑{(j+1)}={1\over2}(z_k↑{(j)}+z\k↑{(j)}$, for
$0\L\|k<\|n-\|j$, for $0\L\|j<\|n$.

\smallskip\noindent
Then
$$B(z_0,z_1,\ldots,z_n;t)=B(z_0↑{(0)},z_0↑{(1)},\ldots,z_0↑{(n)};2t)
=B(z_0↑{(n)},z_1↑{(n-1)},\ldots,z_n↑{(0)};2t-1).$$
This formula gives us the coefficients of polynomials to use over the ranges
$0\L t\L{1\over2}$ and ${1\over2}\L t\L1$.

In our applications it will sometimes be possible to work indirectly with
numbers that allow us to deduce relevant properties of the polynomials
without actually computing the polynomial values. We will deal with
integer coefficients $Z_k=2↑l(z_k-z_{k-1})$ for $1\L\|k\L\|n$, instead of
the actual numbers $z_0$, $z_1$, \dots,~$z_n$, and the value of~\|l will
increase by~1 at each bisection step. This technique reduces the
amount of calculation needed for bisection and also increases the
accuracy of evaluation (since one bit of precision is gained at each
bisection). Indeed, the bisection process now becomes one level shorter:

\smallskip
\textindent{$1'$)} Let $Z_k↑{(1)}=Z_k$, for $1\L\|k\L\|n$.

\smallskip
\textindent{$2'$)} Let $Z_k↑{(j+1)}={1\over2}(Z_k↑{(j)}+Z\k↑{(j)}$, for
$1\L\|k<\|n-\|j$, for $1\L\|j<\|n$.

\smallskip\noindent
The relevant coefficients $(Z'_1,\ldots,Z'_n)$ and $(Z''_1,\ldots,Z''_n)$
for the two subintervals after bisection are respectively
$(Z_1↑{(1)},Z_1↑{(2)},\ldots,Z_1↑{(n)})$ and
$(Z_1↑{(n)},Z_2↑{(n-1)},\ldots,Z_n↑{(1)})$.
And the values of $z_0$ appropriate for the bisected interval are $z'_0=z_0$
and $z''_0=z_0+(Z_1+Z_2+\cdots+Z_n)/2↑{l+1}$.

Step $2'$) involves division by~2, which introduces computational errors
of at most $1\over2$ at each step; thus after $l$~levels of bisection the
integers $Z_k$ will differ from their true values by at most $(n-1)l/2$.
This error rate is quite acceptable, considering that we have $l$~more
bits of precision in the $Z$'s by comparison with the~$z$'s.  Note also
that the $Z$'s remain bounded; there's no danger of integer overflow, even
though $Z_k=2↑l(z_k-z_{k-1})$ for arbitrarily large~$l$.

In fact, we can show not only that the $Z$'s remain bounded, but also that
they become nearly equal, since they are control points for a polynomial
of one less degree. If $\vert Z\k-Z_k\vert\L M$ initially, it is possible
to prove that $\vert Z\k-Z_k\vert\L\lceil M/2↑l\rceil$ after $l$~levels
of bisection, even in the present of rounding errors. Here's the
proof [cf.~Lane and Riesenfeld, {\sl IEEE Trans.\ on Pattern Analysis
and Machine Intelligence\/ \bf PAMI-2} (1980), 35--46]: Assuming that
$\vert Z\k-Z_k\vert\L M$ before bisection, we want to prove that
$\vert Z\k-Z_k\vert\L\lceil M/2\rceil$ afterward. First we show that
$\vert Z\k↑{(j)}-Z_k↑{(j)}\vert\L M$ for all $j$ and~$k$, by induction
on~$j$; this follows from the fact that
$$\bigl\vert\\{half}(a+b)-\\{half}(b+c)\bigr\vert\L
\max\bigl(\vert a-b\vert,\vert b-c\vert\bigr)$$
holds for both of the rounding rules $\\{half}(x)=\lfloor x/2\rfloor$
and $\\{half}(x)={\rm sign}(x)\lfloor\vert x/2\vert\rfloor$.
(If $\vert a-b\vert$ and $\vert b-c\vert$ are equal, then
$a+b$ and $b+c$ are both even or both odd. The rounding errors either
cancel or round the numbers toward each other; hence
$$\eqalign{\bigl\vert\\{half}(a+b)-\\{half}(b+c)\bigr\vert
&\L\bigl\vert{1\over2}(a+b)-{1\over2}(b+c)\bigr\vert\cr
&=\bigl\vert{1\over2}(a-b)+{1\over2}(b-c)\bigr\vert
\L\max\bigl(\vert a-b\vert,\vert b-c\vert\bigr),\cr}$$
as required. A simpler arguments applies if $\vert a-b\vert$ and
$\vert c-b\vert$ are unequal.)  Now it is easy to see that
$\vert Z_1↑{(j+1)}-Z_1↑{(j)}\vert\L\bigl\lfloor{1\over2}
\vert Z_2↑{(j)}-Z_1↑{(j)}\vert+{1\over2}\bigr\rfloor
\L\bigl\lfloor{1\over2}(M+1)\bigr\rfloor=\lceil M/2\rceil$.

Another interesting fact about bisection is the identity
$$Z_1'+\cdots+Z_n'+Z_1''+\cdots+Z_n''=2(Z_1+\cdots+Z_n+E),$$
where $E$ is the sum of the rounding errors in all of the halving
operations ($\vert E\vert\L n(n-1)/4$).

\fi

\M309. We will later reduce the problem of digitizing a complex cubic
$z(t)=B(z_0,z_1,z_2,z_3;t)$ to the following simpler problem:
Given two real cubics
$x(t)=B(x_0,x_1,x_2,x_3;t)$
and $y(t)=B(y_0,y_1,y_2,y_3;t)$ that are monotone nondecreasing,
determine the set of integer points
$$P=\bigl\{\bigl(\lfloor x(t)\rfloor,\lfloor y(t)\rfloor\bigr)
\bigm\vert 0\L t\L 1\bigr\}.$$
Well, the problem isn't actually quite so clean as this; when the path
goes very near an integer point $(a,b)$, computational errors may
make us think that $P$ contains $(a-1,b)$ while in reality it should
contain $(a,b-1)$. Furthermore, if the path goes {\sl exactly\/}
through the integer points $(a-1,b-1)$ and
$(a,b)$, we will want $P$ to contain one
of the two points $(a-1,b)$ or $(a,b-1)$, so that $P$ can be described
entirely by ``rook moves'' upwards or to the right; no diagonal
moves from $(a-1,b-1)$ to~$(a,b)$ will be allowed.

Thus, the set $P$ we wish to compute will merely be an approximation
to the set described in the formula above. It will consist of
$\lfloor x(1)\rfloor-\lfloor x(0)\rfloor$ rightward moves and
$\lfloor y(1)\rfloor-\lfloor y(0)\rfloor$ upward moves, intermixed
in some order. Our job will be to figure out the proper order.

The following recursive strategy suggests itself, when we recall that
$x(0)=x_0$, $x(1)=x_3$, $y(0)=y_0$, and $y(1)=y_3$:

\smallskip\hang
If $\lfloor x_0\rfloor=\lfloor x_3\rfloor$ then take
$\lfloor y_3\rfloor-\lfloor y_0\rfloor$ steps up.

\hang
Otherwise if $\lfloor y_0\rfloor=\lfloor y_3\rfloor$ then take
$\lfloor x_3\rfloor-\lfloor x_0\rfloor$ steps to the right.

\hang
Otherwise bisect the current cubics and repeat the process on both halves.

\yskip\noindent
This intuitively appealing formulation does not quite solve the problem,
because it may never terminate. For example, it's not hard to see that
no steps will {\sl ever\/} be taken if $(x_0,x_1,x_2,x_3)=(y_0,y_1,y_2,y_3)$!
However, we can surmount this difficulty with a bit of care; so let's
proceed to flesh out the algorithm as stated, before worrying about
such details.

The bisect-and-double strategy discussed above suggests that we represent
$(x_0,x_1,x_2,x_3)$ by $(X_1,X_2,X_3)$, where $X_k=2↑l(x_k-x_{k-1})$
for some~$l$. Initially $l=16$, since the $x$'s are \\{scaled}.
In order to deal with other aspects of the algorithm we will want to
maintain also the quantities $m=\lfloor x_3\rfloor-\lfloor x_0\rfloor$
and $R=2↑l(x_0\bmod 1)$. Similarly,
$(y_0,y_1,y_2,y_3)$ will be represented by $(Y_1,Y_2,Y_3)$,
$n=\lfloor y_3\rfloor-\lfloor y_0\rfloor$,
and $S=2↑l(y_0\bmod 1)$. The algorithm now takes the following form:

\smallskip\hang
If $m=0$ then take $n$ steps up.

\hang
Otherwise if $n=0$ then take $n$ steps to the right.

\hang
Otherwise bisect the current cubics and repeat the process on both halves.

\yskip\noindent
The bisection process for $(X_1,X_2,X_3,m,R,l)$ reduces, in essence,
to the following formulas:
$$\vbox{\halign{$#\hfil$\cr
X_2'=\\{half}(X_1+X_2),\quad
X_2''=\\{half}(X_2+X_3),\quad
X_3'=\\{half}(X_2'+X_2'',\cr
X_1'=X_1,\quad
X_1''=X_3',\quad
X_3''=X_3,\cr
R'=2R,\quad
T=X_1+X_1↑{(2)}+X_1↑{(3)}+R',\quad
R''=T\bmod 2↑{l+1},\cr
m'=\lfloor t/2↑{l+1}\rfloor,\quad
m''=m-m'.\cr}}$$

\fi

\M310. When $m=n=1$, the computation can be speeded up because we simply
need to decide between two alternatives, (up,\thinspace right)
versus (right,\thinspace up). There appears to be no simple, direct
way to make the correct decision by looking at the values of
$(X_1,X_2,X_3,R)$ and
$(Y_1,Y_2,Y_3,S)$; but we can streamline the bisection process, and
we can use the fact that only one of the two descendants needs to
be examined after each bisection. Furthermore, we observed earlier
that after several levels of bisection the $X$'s and $Y$'s will be nearly
equal; so we will be justified in assuming that the curve is essentially a
straight line. (This, incidentally, solves the problem of infinite
recursion mentioned earlier.)

It is possible to show that
$$m=\bigl\lfloor(X_1+X_2+X_3+R+E)\,/\,2↑l\bigr\rfloor,$$
where $E$ is an accumulated rounding error that is at most
$3\cdot(2↑{l-16}-1)$ in absolute value. We will make sure that
the $X$'s are less than $2↑{28}$; hence when $l=30$ we must
have $\|m\L1$. This proves that the special case $m=n=1$ is
bound to be reached by the time $l=30$. Furthermore $l=30$ is
a suitable time to make the straight line approximation,
if the recursion hasn't already died out, because the maximum
difference between $X's$ will then be $<2↑{14}$; this corresponds
to an error of $<1$ with respect to the original scaling.
(Stating this another way, each bisection makes the curve two bits
closer to a straight line, hence 14 bisections is sufficient for
28-bit accuracy.)

In the case of a straight line, the curve goes first right, then up,
if and only if $(T-2↑l)(2_l-S)\G(U-2↑l)(2↑l-R)$, where
$T=X_1+X_2+X_3+R$ and $U=Y_1+Y_2+Y_3+S$. For the actual curve
essentially runs from $(R/2↑l,S/2↑l)$ to $(T/2↑l,U/2↑l)$, and
we are testing whether or not $(1,1)$ is on or above the straight
line connecting these two points.

\fi

\M311. One further possibility needs to be mentioned: The algorithm
will be applied only to cubic polynomials $B(x_0,x_1,x_2,x_3;t)$ that
are nondecreasing as $t$~varies from 0 to~1; this condition turns
out to hold if and only if $x_0\L x_1$, $x_2\L x_3$, and either
$x_1\L x_2$ or $(x_1-x_2)↑2\L(x_1-x_0)(x_3-x_2)$. If bisection were
carried out with perfect accuracy, these relations would remain
invariant. But rounding errors can creep in, hence the bisection
algorithm can produce non-monotonic subproblems. This leads to the
potential danger that $m$ or~$n$ could become negative in the
algorithm described above.

For example, if we start with $(x_1-x_0,x_2-x_1,x_3-x_2)=
(X_1,X_2,X_3)=(7,-16,58)$, the corresponding polynomial is
monotonic, because $16↑2<7\cdot39$. But the bisection algorithm
produces the left descendant $(7,-5,3)$, which is nonmonotonic;
its right descendant is~$(0,-1,3)$.

\def\xt{{\tilde x}}
Fortunately we can prove that such rounding errors will never cause
the algorithm to make a tragic mistake. At every stage we are working
with numbers corresponding to a cubic polynomial $B(\xt_0,
\xt_1,\xt_2,\xt_3)$ that approximates some
monotonic polynomial $B(x_0,x_1,x_2,x_3)$. The accumulated errors are
controlled so that $\vert x_k-\xt_k\vert<\epsilon=3\cdot2↑{-16}$.
If bisection is done at some stage of the recursion, we have
$m=\lfloor\xt_3\rfloor-\lfloor\xt_0\rfloor>0$, and the algorithm
computes a bisection value $\bar x$ such that $m'=\lfloor\bar x\rfloor$
and $m''=\lfloor\xt_3\rfloor-\lfloor\bar x\rfloor$. We want to prove
that neither $m'$ nor $m''$ can be negative. Since $\bar x$ is an
approximation to a value in the interval $[x_0,x_3]$, we have
$\bar x>x_0-\epsilon$ and $\bar x<x_3+\epsilon$, hence $\bar x>
\xt_0-2\epsilon$ and $\bar<\xt_3+2\epsilon$.
If $m'$ is negative we must have $\xt_0\bmod 1<2\epsilon$;
if $m''$ is negative we must have $\xt_3\bmod 1>1-2\epsilon$.
In either case the condition $\lfloor\xt_3\rfloor-\lfloor\xt_0\rfloor>0$
$\xt_3-\xt_0>1-2\epsilon$, hence $x_3-x_0>1-4\epsilon$.
But it can be shown that if $B(x_0,x_1,x_2,x_3;t)$ is a monotonic
cubic, then $B(x_0,x_1,x_2,x_3;{1\over2})$ is always between
$.14[x_0,x_3]$ and $.86[x_0,x_3]$; and it is impossible for $\bar x$
to be within~$\epsilon$ of such a number. Contradiction!
(The constant .14 is actually $(7-\sqrt{28}/12$; the worst case
occurs for polynomials like $B(0,28-4\sqrt{28},14-5\sqrt{28},42)$.)

\fi

\M312. OK, now that a long theoretical preamble has justified the
bisection-and-doubling algorithm, we are ready to proceed with
its actual coding. But we still haven't discussed the
form of the output.

For reasons to be discussed later, we shall find it convenient to
record the output as follows: Moving one step up is represented by
appending a `1' to a list; moving one step right is represented by
adding unity to the element at the end of the list. Thus, for example,
the net effect of ``(up, right, right, up, right)'' is to append
$(3,2)$.

The list is kept in a global array called \\{move}. Before starting the
algorithm, \MF\ should check that $\\{move\_ptr}+\lfloor y_3\rfloor
-\lfloor y_0\rfloor\L\\{move\_size}$, so that the list won't exceed
the bounds of this array.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{move}: \37\&{array} $[-1\to\\{move\_size}]$ \1\&{of}\5
\\{integer};\C{the recorded moves}\2\6
\4\\{move\_ptr}: \37$0\to\\{move\_size}$;\C{the number of items in the \\{move}
list}\par
\fi

\M313. A special negative entry at the low end of \\{move} proves to be handy.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{move}[-1]\K-1$;\par
\fi

\M314. When bisection occurs, we ``push'' the subproblem corresponding
to the right-hand subinterval onto the \\{bisect\_stack} while
we continue to work on the left-hand subinterval. Thus, the \\{bisect\_stack}
will hold $(X_1,X_2,X_3,R,m,Y_1,Y_2,Y_3,S,n,l)$ values for
subproblems yet to be tackled.

At most 14 subproblems will be on the stack at once (namely, for
$l=16$,~17, \dots,~29); but the stack is bigger than this, because
it is used also for more complicated bisection algorithms.

\Y\P\D \37$\\{stack\_x1}\S\\{bisect\_stack}[\\{bisect\_ptr}]$\C{stacked value
of $X_1$}\par
\P\D \37$\\{stack\_x2}\S\\{bisect\_stack}[\\{bisect\_ptr}+1]$\C{stacked value
of $X_2$}\par
\P\D \37$\\{stack\_x3}\S\\{bisect\_stack}[\\{bisect\_ptr}+2]$\C{stacked value
of $X_3$}\par
\P\D \37$\\{stack\_r}\S\\{bisect\_stack}[\\{bisect\_ptr}+3]$\C{stacked value of
$R$}\par
\P\D \37$\\{stack\_m}\S\\{bisect\_stack}[\\{bisect\_ptr}+4]$\C{stacked value of
$m$}\par
\P\D \37$\\{stack\_y1}\S\\{bisect\_stack}[\\{bisect\_ptr}+5]$\C{stacked value
of $Y_1$}\par
\P\D \37$\\{stack\_y2}\S\\{bisect\_stack}[\\{bisect\_ptr}+6]$\C{stacked value
of $Y_2$}\par
\P\D \37$\\{stack\_y3}\S\\{bisect\_stack}[\\{bisect\_ptr}+7]$\C{stacked value
of $Y_3$}\par
\P\D \37$\\{stack\_s}\S\\{bisect\_stack}[\\{bisect\_ptr}+8]$\C{stacked value of
$S$}\par
\P\D \37$\\{stack\_n}\S\\{bisect\_stack}[\\{bisect\_ptr}+9]$\C{stacked value of
$n$}\par
\P\D \37$\\{stack\_l}\S\\{bisect\_stack}[\\{bisect\_ptr}+10]$\C{stacked value
of $l$}\par
\P\D \37$\\{move\_increment}=11$\C{number of items pushed by \\{make\_moves}}%
\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{bisect\_stack}: \37\&{array} $[0\to\\{bistack\_size}]$ \1\&{of}\5
\\{integer};\2\6
\4\\{bisect\_ptr}: \37$0\to\\{bistack\_size}$;\par
\fi

\M315. \P$\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $14\ast\\{move\_increment}>\\{bistack\_size}$ \1\&{then}\5
$\\{bad}\K21$;\2\par
\fi

\M316. The \\{make\_moves} subroutine is given \\{scaled} values
$(x_0,x_1,x_2,x_3)$
and $(y_0,y_1,y_2,y_3)$ that represent monotone-nondecreasing polynomials;
it makes $\lfloor x_3\rfloor-\lfloor x_0\rfloor$ rightward moves and
$\lfloor y_3\rfloor-\lfloor y_0\rfloor$ upward moves, as explained earlier.
(Here $\lfloor x\rfloor$ actually stands for $\lfloor x/2↑{16}\rfloor$,
if $x$ is regarded as an integer without scaling.) The unscaled integers
$x_k$ and~$y_k$ should be less than $2↑{28}$ in magnitude; this, together
with the monotonicity condition, implies that $\vert x\k-x_k\vert$
and $\vert y\k-y_k\vert$ are also less than~$2↑{28}$.

It is assumed that $\\{move\_ptr}+\lfloor y_3\rfloor-\lfloor y_0\rfloor
<\\{move\_size}$ when this procedure is called, so that the capacity of
the \\{move} array will not be exceeded.

\Y\P\4\&{procedure}\1\  \37$\\{make\_moves}(\\{xx0},\39\\{xx1},\39\\{xx2},\39%
\\{xx3},\39\\{yy0},\39\\{yy1},\39\\{yy2},\39\\{yy3}:\\{scaled})$;\6
\4\&{label} \37$\\{continue},\39\\{done},\39\\{exit}$;\6
\4\&{var} \37$\\{x1},\39\\{x2},\39\\{x3},\39\|m,\39\|r,\39\\{y1},\39\\{y2},\39%
\\{y3},\39\|n,\39\|s,\39\|l$: \37\\{integer};\C{bisection variables explained
above}\6
$\|q,\39\|t,\39\|u,\39\\{x2a},\39\\{x3a},\39\\{y2a},\39\\{y3a}$: \37%
\\{integer};\C{additional temporary registers}\2\6
\&{begin} \37$\|l\K16$;\5
$\\{bisect\_ptr}\K0$;\6
$\\{x1}\K\\{xx1}-\\{xx0}$;\5
$\\{x2}\K\\{xx2}-\\{xx1}$;\5
$\\{x3}\K\\{xx3}-\\{xx2}$;\6
\&{if} $\\{xx0}\G0$ \1\&{then}\5
$\|r\K\\{xx0}\mathbin{\&{mod}}\\{unity}$\6
\4\&{else} $\|r\K\\{unity}-1-((-\\{xx0}-1)\mathbin{\&{mod}}\\{unity})$;\2\6
$\|m\K(\\{xx3}-\\{xx0}+\|r)\mathbin{\&{div}}\\{unity}$;\6
$\\{y1}\K\\{yy1}-\\{yy0}$;\5
$\\{y2}\K\\{yy2}-\\{yy1}$;\5
$\\{y3}\K\\{yy3}-\\{yy2}$;\6
\&{if} $\\{yy0}\G0$ \1\&{then}\5
$\|s\K\\{yy0}\mathbin{\&{mod}}\\{unity}$\6
\4\&{else} $\|s\K\\{unity}-1-((-\\{yy0}-1)\mathbin{\&{mod}}\\{unity})$;\2\6
$\|n\K(\\{yy3}-\\{yy0}+\|s)\mathbin{\&{div}}\\{unity}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37\X318:Make moves for current
subinterval; if bisection is necessary, push the second subinterval onto the
stack,and \&{goto} \\{continue} in order to handle the first subinterval\X;\6
\&{if} $\\{bisect\_ptr}=0$ \1\&{then}\5
\&{return};\2\6
\X317:Remove a subproblem for \\{make\_moves} from the stack\X;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M317. \P$\X317:Remove a subproblem for \\{make\_moves} from the stack\X\S$\6
$\\{bisect\_ptr}\K\\{bisect\_ptr}-\\{move\_increment}$;\6
$\\{x1}\K\\{stack\_x1}$;\5
$\\{x2}\K\\{stack\_x2}$;\5
$\\{x3}\K\\{stack\_x3}$;\5
$\|r\K\\{stack\_r}$;\5
$\|m\K\\{stack\_m}$;\6
$\\{y1}\K\\{stack\_y1}$;\5
$\\{y2}\K\\{stack\_y2}$;\5
$\\{y3}\K\\{stack\_y3}$;\5
$\|s\K\\{stack\_s}$;\5
$\|n\K\\{stack\_n}$;\6
$\|l\K\\{stack\_l}$\par
\U section~316.\fi

\M318. \P$\X318:Make moves for current subinterval; if bisection is necessary,
push the second subinterval onto the stack,and \&{goto} \\{continue} in order
to handle the first subinterval\X\S$\6
\&{if} $\|m=0$ \1\&{then}\5
\X319:Move upward \|n steps\X\6
\4\&{else} \&{if} $\|n=0$ \1\&{then}\5
\X320:Move to the right \|m steps\X\6
\4\&{else} \&{if} $\|m+\|n=2$ \1\&{then}\5
\X321:Make one move of each kind\X\6
\4\&{else} \&{begin} \37$\\{incr}(\|l)$;\5
$\\{stack\_l}\K\|l$;\6
$\\{stack\_x3}\K\\{x3}$;\5
$\\{stack\_x2}\K\\{half}(\\{x2}+\\{x3})$;\5
$\\{x2}\K\\{half}(\\{x1}+\\{x2})$;\5
$\\{x3}\K\\{half}(\\{x2},\39\\{stack\_x2})$;\5
$\\{stack\_x1}\K\\{x3}$;\6
$\|r\K\|r+\|r$;\5
$\|t\K\\{x1}+\\{x2}+\\{x3}+\|r$;\6
$\|q\K\|t\mathbin{\&{div}}\\{two\_to\_the}[\|l]$;\5
$\\{stack\_r}\K\|t\mathbin{\&{mod}}\\{two\_to\_the}[\|l]$;\6
$\\{stack\_m}\K\|m-\|q$;\5
$\|m\K\|q$;\6
$\\{stack\_y3}\K\\{y3}$;\5
$\\{stack\_y2}\K\\{half}(\\{y2}+\\{y3})$;\5
$\\{y2}\K\\{half}(\\{y1}+\\{y2})$;\5
$\\{y3}\K\\{half}(\\{y2},\39\\{stack\_y2})$;\5
$\\{stack\_y1}\K\\{y3}$;\6
$\|s\K\|s+\|s$;\5
$\|u\K\\{y1}+\\{y2}+\\{y3}+\|s$;\6
$\|q\K\|u\mathbin{\&{div}}\\{two\_to\_the}[\|l]$;\5
$\\{stack\_s}\K\|u\mathbin{\&{mod}}\\{two\_to\_the}[\|l]$;\6
$\\{stack\_n}\K\|n-\|q$;\5
$\|n\K\|q$;\6
$\\{bisect\_ptr}\K\\{bisect\_ptr}+\\{move\_increment}$;\5
\&{goto} \37\\{continue};\6
\&{end}\2\2\2\par
\U section~316.\fi

\M319. \P$\X319:Move upward \|n steps\X\S$\6
\&{while} $\|n>0$ \1\&{do}\6
\&{begin} \37$\\{incr}(\\{move\_ptr})$;\5
$\\{move}[\\{move\_ptr}]\K1$;\5
$\\{decr}(\|n)$;\6
\&{end}\2\par
\U section~318.\fi

\M320. \P$\X320:Move to the right \|m steps\X\S$\6
$\\{move}[\\{move\_ptr}]\K\\{move}[\\{move\_ptr}]+\|m$\par
\U section~318.\fi

\M321. \P$\X321:Make one move of each kind\X\S$\6
$\|r\K\\{two\_to\_the}[\|l]-\|r$;\5
$\|s\K\\{two\_to\_the}[\|l]-\|s$;\6
\&{while} $\|l<30$ \1\&{do}\6
\&{begin} \37$\\{x3a}\K\\{x3}$;\5
$\\{x2a}\K\\{half}(\\{x2}+\\{x3})$;\5
$\\{x2}\K\\{half}(\\{x1}+\\{x2})$;\5
$\\{x3}\K\\{half}(\\{x2}+\\{x2a})$;\5
$\|t\K\\{x1}+\\{x2}+\\{x3}$;\5
$\|r\K\|r+\|r$;\6
$\\{y3a}\K\\{y3}$;\5
$\\{y2a}\K\\{half}(\\{y2}+\\{y3})$;\5
$\\{y2}\K\\{half}(\\{y1}+\\{y2})$;\5
$\\{y3}\K\\{half}(\\{y2}+\\{y2a})$;\5
$\|u\K\\{y1}+\\{y2}+\\{y3}$;\5
$\|s\K\|s+\|s$;\6
\&{if} $\|t<\|r$ \1\&{then}\6
\&{if} $\|u<\|s$ \1\&{then}\5
\X322:Switch to the right subinterval\X\6
\4\&{else} \&{begin} \37\X324:Move up then right\X;\6
\&{goto} \37\\{done};\6
\&{end}\2\6
\4\&{else} \&{if} $\|u<\|s$ \1\&{then}\6
\&{begin} \37\X323:Move right then up\X;\6
\&{goto} \37\\{done};\6
\&{end};\2\2\6
$\\{incr}(\|l)$;\6
\&{end};\2\6
\4\\{done}: \37\&{if} $\\{ab\_geq\_cd}(\|t-\|r,\39\|s,\39\|u-\|s,\39\|r)$ \1%
\&{then}\5
\X323:Move right then up\X\6
\4\&{else} \X324:Move up then right\X\2\par
\U section~318.\fi

\M322. FIXTHIS: check original notes, since the code was dropped out!

\Y\P$\4\X322:Switch to the right subinterval\X\S$\6
\&{begin} \37$\\{x3}\K\\{x3a}$;\5
$\\{x2}\K\\{x2a}$;\5
$\\{x1}\K\\{x3}$;\5
$\|r\K\|r-\|t$;\C{?}\6
$\\{y3}\K\\{y3a}$;\5
$\\{y2}\K\\{y2a}$;\5
$\\{y1}\K\\{y3}$;\5
$\|s\K\|s-\|u$;\C{?}\6
\&{end}\par
\U section~321.\fi

\M323. \P$\X323:Move right then up\X\S$\6
\&{begin} \37$\\{incr}(\\{move}[\\{move\_ptr}])$;\5
$\\{incr}(\\{move\_ptr})$;\5
$\\{move}[\\{move\_ptr}]\K1$;\6
\&{end}\par
\U sections~321 and~321.\fi

\M324. \P$\X324:Move up then right\X\S$\6
\&{begin} \37$\\{incr}(\\{move\_ptr})$;\5
$\\{move}[\\{move\_ptr}]\K2$;\6
\&{end}\par
\U sections~321 and~321.\fi

\M325. After \\{make\_moves} has acted, possibly for several curves that move
toward
the same octant, a ``smoothing'' operation is done on the \\{move} array.
This removes optical glitches that can arise even when the curve has been
digitized without rounding errors.

The smoothing process simply replaces the patterns of consecutive
elements $(a\pm1,a\mp1,a)$ and $(a,a\pm1,a\mp1)$ by~$(a,a,a)$.

We assume that \\{move\_ptr} is strictly less than \\{move\_size}.

\Y\P\4\&{procedure}\1\  \37\\{smooth\_moves};\6
\4\&{label} \37$\\{continue},\39\\{exit}$;\6
\4\&{var} \37\|k: \37$1\to\\{move\_size}$;\C{index into \\{move}}\6
\|a: \37\\{integer};\C{smoother value}\2\6
\&{begin} \37\&{if} $\\{move\_ptr}\G2$ \1\&{then}\6
\&{begin} \37$\|k\K1$;\5
$\\{move}[\\{move\_ptr}+1]\K-1$;\C{impossible value}\6
\4\\{continue}: \37\&{if} $\\{abs}(\\{move}[\|k-1]-\\{move}[\|k])=2$ \1\&{then}%
\6
\&{begin} \37$\|a\K\\{half}(\\{move}[\|k-1]+\\{move}[\|k])$;\6
\&{if} $\\{move}[\|k-2]=\|a$ \1\&{then}\6
\&{begin} \37$\\{move}[\|k-1]\K\|a$;\5
$\\{move}[\|k]\K\|a$;\6
\&{end}\6
\4\&{else} \&{if} $\\{move}[\|k+1]=\|a$ \1\&{then}\6
\&{begin} \37$\\{move}[\|k-1]\K\|a$;\5
$\\{move}[\|k]\K\|a$;\6
\&{if} $\|k>1$ \1\&{then}\6
\&{begin} \37$\\{decr}(\|k)$;\5
\&{goto} \37\\{continue};\6
\&{end};\2\6
\&{end};\2\2\6
\&{end};\2\6
\&{if} $\|k=\\{move\_ptr}$ \1\&{then}\5
\&{return};\2\6
$\\{incr}(\|k)$;\5
\&{goto} \37\\{continue};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\N326.  \[xx] Edge structures.
Now we come to \MF's internal scheme for representing what the user can
actually ``see,'' the edges between pixels. Each pixel has an integer
weight, obtained by summing the weights on all edges to its left. \MF\
represents only the nonzero edge weights, since most of the edges are
weightless; in this way, the data storage requirements grow only linearly
with respect to the number of pixels per point, even though two-dimensional
data is being represented. (Well, the actual dependence on the underlying
resolution is order $n\log n$, but the the $\log n$ factor is buried in our
implicit restriction on the maximum raster size.) The sum of all edge
weights in each row should be zero.

The data structure for edge weights must be compact and flexible,
yet it should support efficient updating and display operations. We
want to be able to have many different edge structures in memory at
once, and we want the computer to be able to translate them, reflect them,
or merge them together with relative ease.

\MF's solution to this problem requires one single-word node per
nonzero edge weight, plus one two-word node for each row in a contiguous
set of rows. There's also a header node that provides global information
about the entire structure.

\fi

\M327. Let's consider the edge-weight nodes first. The \\{info} field of such
nodes contains both an $m$~value and a weight~$w$, in the form
$8m+w+c$, where $c$ is a constant that depends on data found in the header.
We shall consider $c$ in detail later; for now, it's best just to think
of it as a way to compensate for the fact that $m$ and~$w$ can be negative,
together with the fact that an \\{info} field must have a value between
\\{min\_halfword} and \\{max\_halfword}. The $m$ value is an unscaled
$x$-coordinate,
so it satisfies $\vert m\vert<
4096$; the $w$ value is always in the range $1\L\vert w\vert\L3$. We can
unpack the data in the \\{info} field by fetching $\\{ho}(\\{info}(\|p))=%
\\{info}(\|p)-\\{min\_halfword}$ and dividing this nonnegative number by~8;
the constant~$c$ will be chosen so that the remainder of this division
is $4+w$. Thus, for example, a remainder of~3 will correspond to
the edge weight $w=-1$.

Every row of an edge structure contains two lists of such edge-weight
nodes, called the \\{sorted} and \\{unsorted} lists, linked together by their
\\{link} fields in the normal way. The difference between them is that we
always have $\\{info}(\|p)\L\\{info}(\\{link}(\|p))$ in the \\{sorted} list,
but there's no
such restriction on the elements of the \\{unsorted} list. The reason for
this distinction is that it would take unnecessarily long to maintain
edge-weight lists in sorted order when they're being updated; and when we
need to process an entire row from left to right in order of the
$m$~values, it's fairly easy and quick to sort a short list of unsorted
elements and to merge them into place among their sorted cohorts.
Furthermore, the fact that the \\{unsorted} list is empty can sometimes be
used to good advantage, because it allows us to conclude that a particular
row has not changed since the last time we sorted it.

The final \\{link} of the \\{sorted} list will be \\{sentinel}, which points to
a special one-word node whose \\{info} field is essentially infinite; this
facilitates the sorting and merging operations. The final \\{link} of the
\\{unsorted} list will be either \\{null} or \\{null1}, where $\\{null1}=%
\\{null}+1$
is used to avoiding redisplaying data that has not changed:
A \\{null1} value is stored at the head of the
unsorted list whenever the corresponding has been displayed.

\Y\P\D \37$\\{zero\_w}=4$\par
\P\D \37$\\{null1}\S\\{null}+1$\par
\Y\P$\4\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}\S$\6
$\\{info}(\\{sentinel})\K\\{max\_halfword}$;\par
\fi

\M328. The rows themselves are represented by row-header nodes that
contain four link fields. Two of these four, \\{sorted} and \\{unsorted},
point to the first items of the edge-weight lists just mentioned.
The other two, \\{link} and \\{knil}, point to the headers of the two
adjacent rows; if \|p points to the header for row number~\|n, then
$\\{link}(\|p)$ points to the header for row~$\|n+1$, and $\\{knil}(\|p)$
points
to the header for row~$\|n-1$. This double linking makes it
convenient to move through consecutive rows either upward or downward;
as usual, we have $\\{link}(\\{knil}(\|p))=\\{knil}(\\{link}(\|p))=\|p$ for all
row headers~\|p.

The row associated with a given value of \|n contains weights for
edges that run between the lattice points $(\|m,\|n)$ and $(\|m,\|n+1)$.

\Y\P\D \37$\\{knil}\S\\{info}$\C{inverse of the \\{link} field, in a doubly
linked list}\par
\P\D \37$\\{sorted\_loc}(\#)\S\#+1$\C{where the \\{sorted} link field resides}%
\par
\P\D \37$\\{sorted}(\#)\S\\{link}(\\{sorted\_loc}(\#))$\C{beginning of the list
of sorted edge weights}\par
\P\D \37$\\{unsorted}(\#)\S\\{info}(\#+1)$\C{beginning of the list of unsorted
edge weights}\par
\P\D \37$\\{row\_node\_size}=2$\C{number of words in a row header node}\par
\fi

\M329. The main header node \|h for an edge structure has \\{link} and \\{knil}
fields that link it above the topmost row and below the bottommost row.
It also has fields called \\{m\_min}, \\{m\_max}, \\{n\_min}, and \\{n\_max}
that
bound the current extent of the edge data: All \|m values in edge-weight
nodes should lie between $\\{m\_min}(\|h)-4096$ and $\\{m\_max}(\|h)-4096$,
inclusive.
Furthermore the topmost row header, pointed to by $\\{knil}(\|h)$,
is for row number $\\{n\_max}(\|h)-4096$; the bottommost row header, pointed to
by
$\\{link}(\|h)$, is for row number $\\{n\_min}(\|h)-4096$.

The offset constant \|c that's used in all of the edge-weight data is
represented implicitly in $\\{m\_offset}(\|h)$; its actual value is
$$\hbox{$\|c=\\{min\_halfword}+\\{zero\_w}+8\ast\\{m\_offset}(\|h)$.}$$
Notice that it's possible to shift an entire edge structure by an
amount $(\Delta m,\Delta n)$ by adding $\Delta n$ to $\\{n\_min}(\|h)$ and $%
\\{n\_max}(\|h)$,
adding $\Delta m$ to $\\{m\_min}(\|h)$ and $\\{m\_max}(\|h)$, and subtracting
$\Delta m$ from $\\{m\_offset}(\|h)$;
none of the other edge data needs to be modified. Initially the \\{m\_offset}
field is~4096, but it will change if the user requests such a shift.
The contents of these five fields should always be positive and less than
8192; furthermore $\\{m\_min}+\\{m\_offset}$ and
$\\{m\_max}-\\{m\_offset}$ must also be between 0 and 8192, so that the
\\{info} fields of edge-weight nodes will fit in a halfword.

The header node of an edge structure also contains two somewhat unusual
fields called $\\{last\_window}(\|h)$ and $\\{last\_window\_time}(\|h)$. When
this
structure is displayed in window~\|k of the user's screen, after that
window has been updated \|m times, \MF\ sets $\\{last\_window}(\|h)\K\|k$ and
$\\{last\_window\_time}(\|h)\K\|m$; it also sets $\\{unsorted}(\|p)\K\\{null1}$
for all row
headers~\|p, after merging any existing unsorted weights with the sorted
ones.  A subsequent display in the same window will be able to avoid
redisplaying rows whose \\{unsorted} list is still \\{null1}, if the window
hasn't been used for something else in the meantime.

A pointer to the row header of row $\\{n\_pos}(\|h)-4096$ is provided in
$\\{n\_rover}(\|h)$. Most of the algorithms that update an edge structure
are able to get by without random row references; they usually
access rows that are neighbors of each other or of the current \\{n\_pos} row.

\Y\P\D \37$\\{zero\_field}=4096$\C{amount added to coordinates to make them
positive}\par
\P\D \37$\\{n\_min}(\#)\S\\{info}(\#+1)$\C{minimum row number present, plus %
\\{zero\_field}}\par
\P\D \37$\\{n\_max}(\#)\S\\{link}(\#+1)$\C{maximum row number present, plus %
\\{zero\_field}}\par
\P\D \37$\\{m\_min}(\#)\S\\{info}(\#+2)$\C{minimum column number present, plus %
\\{zero\_field}}\par
\P\D \37$\\{m\_max}(\#)\S\\{link}(\#+2)$\C{maximum column number present, plus %
\\{zero\_field}}\par
\P\D \37$\\{m\_offset}(\#)\S\\{info}(\#+3)$\C{translation of $m$ data in
edge-weight nodes}\par
\P\D \37$\\{last\_window}(\#)\S\\{link}(\#+3)$\C{the last display went into
this window}\par
\P\D \37$\\{last\_window\_time}(\#)\S\\{mem}[\#+4].\\{int}$\C{after this many
window update}\par
\P\D \37$\\{n\_pos}(\#)\S\\{info}(\#+5)$\C{the row currently in \\{n\_rover},
plus \\{zero\_field}}\par
\P\D \37$\\{n\_rover}(\#)\S\\{link}(\#+5)$\C{a row recently referenced}\par
\P\D \37$\\{edge\_header\_size}=6$\C{number of words in an edge-structure
header}\par
\Y\P\4\&{procedure}\1\  \37\\{new\_edges}: \37\\{pointer};\C{creates a new
(empty) edge structure}\6
\4\&{var} \37\|h: \37\\{pointer};\C{the new header node}\2\6
\&{begin} \37$\|h\K\\{get\_node}(\\{edge\_header\_size})$;\5
$\\{knil}(\|h)\K\|h$;\5
$\\{link}(\|h)\K\|h$;\6
$\\{n\_min}(\|h)\K\\{zero\_field}+4095$;\5
$\\{n\_max}(\|h)\K\\{zero\_field}-4095$;\5
$\\{m\_min}(\|h)\K\\{zero\_field}+4095$;\5
$\\{m\_max}(\|h)\K\\{zero\_field}-4095$;\5
$\\{m\_offset}(\|h)\K\\{zero\_field}$;\6
$\\{last\_window}(\|h)\K0$;\5
$\\{last\_window\_time}(\|h)\K0$;\6
$\\{n\_rover}(\|h)\K\|h$;\5
$\\{n\_pos}(\|h)\K\\{n\_max}(\|h)+1$;\6
$\\{new\_edges}\K\|h$;\6
\&{end};\par
\fi

\M330. When a lot of work is being done on a particular edge structure, we
plant
a pointer to its main header in the global variable \\{cur\_edges}.
This saves us from having to pass this pointer as a parameter over and
over again between subroutines.

Similarly, \\{cur\_wt} is a global weight that is being used by several
procedures at once.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_edges}: \37\\{pointer};\C{the edge structure of current interest}\6
\4\\{cur\_wt}: \37\\{integer};\C{the edge weight of current interest}\par
\fi

\M331. The \\{edge\_prep} routine makes the \\{cur\_edges} structure ready to
accept new data whose coordinates satisfy $\\{ml}\L\|m\L\\{mr}$ and $\\{nl}\L%
\|n\L\\{nr}$,
assuming that $-4096<\\{ml},\\{mr},\\{nl},\\{nr}<4096$. It makes appropriate
adjustments to \\{m\_min}, \\{m\_max}, \\{n\_min}, and \\{n\_max}, adding
new empty rows if necessary. In unusual cases it will also go through
all of the edge-weight nodes and add a constant to their \\{info}
fields; this is necessary only if the \\{m\_offset} has gotten too
large or too small.

\Y\P\4\&{procedure}\1\  \37$\\{edge\_prep}(\\{ml},\39\\{mr},\39\\{nl},\39%
\\{nr}:\\{integer})$;\6
\4\&{var} \37\\{delta}: \37\\{halfword};\C{amount of change}\6
$\|p,\39\|q$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37$\\{ml}\K\\{ml}+\\{zero\_field}$;\5
$\\{mr}\K\\{mr}+\\{zero\_field}$;\5
$\\{nl}\K\\{nl}+\\{zero\_field}$;\5
$\\{nr}\K\\{nr}+\\{zero\_field}$;\6
\&{if} $\\{ml}<\\{m\_min}(\\{cur\_edges})$ \1\&{then}\5
$\\{m\_min}(\\{cur\_edges})\K\\{ml}$;\2\6
\&{if} $\\{mr}<\\{m\_max}(\\{cur\_edges})$ \1\&{then}\5
$\\{m\_max}(\\{cur\_edges})\K\\{mr}$;\2\6
\&{if} $(\\{abs}(\\{m\_min}(\\{cur\_edges})-\\{m\_offset}(\\{cur\_edges}))\G%
\\{zero\_field})\V\30(\\{abs}(\\{m\_max}(\\{cur\_edges})-\\{m\_offset}(\\{cur%
\_edges}))\G\\{zero\_field})$ \1\&{then}\5
\X334:Change the edge data so that $\\{m\_offset}(\\{cur\_edges})=\\{zero%
\_field}$\X;\2\6
\&{if} $\\{link}(\\{cur\_edges})=\\{cur\_edges}$ \1\&{then}\C{there are no
rows}\6
\&{begin} \37$\\{n\_min}(\\{cur\_edges})\K\\{nr}+1$;\5
$\\{n\_max}(\\{cur\_edges})\K\\{nr}$;\5
$\\{n\_pos}(\\{cur\_edges})\K\\{nr}+1$;\C{$\\{n\_rover}(\\{cur\_edges})=\\{cur%
\_edges}$}\6
\&{end};\2\6
\&{if} $\\{nl}<\\{n\_min}(\\{cur\_edges})$ \1\&{then}\5
\X332:Insert $\\{n\_min}(\\{cur\_edges})-\\{nl}$ empty rows at the bottom\X;\2\6
\&{if} $\\{nr}>\\{n\_max}(\\{cur\_edges})$ \1\&{then}\5
\X333:Insert $\\{nr}-\\{n\_max}(\\{cur\_edges})$ empty rows at the top\X;\2\6
\&{end};\par
\fi

\M332. \P$\X332:Insert $\\{n\_min}(\\{cur\_edges})-\\{nl}$ empty rows at the
bottom\X\S$\6
\&{begin} \37$\\{delta}\K\\{n\_min}(\\{cur\_edges})-\\{nl}$;\5
$\\{n\_min}(\\{cur\_edges})\K\\{nl}$;\5
$\|p\K\\{link}(\\{cur\_edges})$;\6
\1\&{repeat} \37$\|q\K\\{get\_node}(\\{row\_node\_size})$;\5
$\\{sorted}(\|q)\K\\{sentinel}$;\5
$\\{unsorted}(\|q)\K\\{null1}$;\5
$\\{knil}(\|p)\K\|q$;\5
$\\{link}(\|q)\K\|p$;\5
$\|p\K\|q$;\5
$\\{decr}(\\{delta})$;\6
\4\&{until}\5
$\\{delta}=0$;\2\6
$\\{knil}(\|p)\K\\{cur\_edges}$;\5
$\\{link}(\\{cur\_edges})\K\|p$;\6
\&{end}\par
\U section~331.\fi

\M333. \P$\X333:Insert $\\{nr}-\\{n\_max}(\\{cur\_edges})$ empty rows at the
top\X\S$\6
\&{begin} \37$\\{delta}\K\\{nr}-\\{n\_max}(\\{cur\_edges})$;\5
$\\{n\_max}(\\{cur\_edges})\K\\{nr}$;\5
$\|p\K\\{knil}(\\{cur\_edges})$;\6
\1\&{repeat} \37$\|q\K\\{get\_node}(\\{row\_node\_size})$;\5
$\\{sorted}(\|q)\K\\{sentinel}$;\5
$\\{unsorted}(\|q)\K\\{null1}$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{knil}(\|q)\K\|p$;\5
$\|p\K\|q$;\5
$\\{decr}(\\{delta})$;\6
\4\&{until}\5
$\\{delta}=0$;\2\6
$\\{link}(\|p)\K\\{cur\_edges}$;\5
$\\{knil}(\\{cur\_edges})\K\|p$;\6
\&{end}\par
\U section~331.\fi

\M334. \P$\X334:Change the edge data so that $\\{m\_offset}(\\{cur\_edges})=%
\\{zero\_field}$\X\S$\6
\&{begin} \37$\\{delta}\K8\ast(\\{m\_offset}(\\{cur\_edges})-\\{zero\_field})$;%
\5
$\\{m\_offset}(\\{cur\_edges})\K\\{zero\_field}$;\5
$\|q\K\\{link}(\\{cur\_edges})$;\6
\&{while} $\|q\I\\{cur\_edges}$ \1\&{do}\6
\&{begin} \37$\|p\K\\{sorted}(\|q)$;\6
\&{while} $\|p>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\\{info}(\|p)\K\\{info}(\|p)-\\{delta}$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\|p\K\\{unsorted}(\|q)$;\6
\&{while} $\|p>\\{null1}$ \1\&{do}\6
\&{begin} \37$\\{info}(\|p)\K\\{info}(\|p)-\\{delta}$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\&{end}\par
\U section~331.\fi

\M335. The \\{print\_edges} subroutine gives a symbolic rendition of an edge
structure, for use in `\&{show}' commands. A rather terse output
format has been chosen since edge structures can grow quite large.

\Y\P\X336:Declare the procedure called \\{print\_weight}\X\6
\4\&{procedure}\1\  \37$\\{print\_edges}(\|h:\\{pointer};\,\35\|s:\\{str%
\_number})$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for list traversal}\6
\|n: \37\\{integer};\C{row number}\2\6
\&{begin} \37$\\{print\_diagnostic}(\.{"Edge\ structure"},\39\|s)$;\5
$\|p\K\\{knil}(\|h)$;\5
$\|n\K\\{n\_max}(\|h)-\\{zero\_field}$;\5
$\\{cur\_edges}\K\|h$;\6
\&{while} $\|p\I\|h$ \1\&{do}\6
\&{begin} \37$\\{print\_nl}(\.{"row\ "})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print\_char}(\.{":"})$;\5
$\|q\K\\{unsorted}(\|p)$;\6
\&{while} $\|q>\\{null1}$ \1\&{do}\6
\&{begin} \37$\\{print\_weight}(\|q)$;\5
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
$\\{print}(\.{"\ |"})$;\5
$\|q\K\\{sorted}(\|p)$;\6
\&{while} $\|q>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\\{print\_weight}(\|q)$;\5
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
$\|p\K\\{knil}(\|p)$;\5
$\\{decr}(\|n)$;\6
\&{end};\2\6
$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\par
\fi

\M336. \P$\X336:Declare the procedure called \\{print\_weight}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_weight}(\|q:\\{pointer})$;\6
\4\&{var} \37$\|w,\39\|m$: \37\\{integer};\C{unpacked weight and coordinate}\6
\|z: \37\\{integer};\C{temporary register}\2\6
\&{begin} \37$\|z\K\\{ho}(\|q)$;\5
$\|w\K\|z\mathbin{\&{mod}}8$;\5
$\|m\K(\|z\mathbin{\&{div}}8)-\\{m\_offset}(\\{cur\_edges})$;\6
\&{if} $\\{file\_offset}>\\{max\_print\_line}-9$ \1\&{then}\5
$\\{print\_nl}(\.{"\ "})$\6
\4\&{else} $\\{print\_char}(\.{"\ "})$;\2\6
$\\{print\_int}(\|m)$;\6
\&{while} $\|w>\\{zero\_w}$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\.{"+"})$;\5
$\\{decr}(\|w)$;\6
\&{end};\2\6
\&{while} $\|w<\\{zero\_w}$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\.{"-"})$;\5
$\\{incr}(\|w)$;\6
\&{end};\2\6
\&{end};\par
\U section~335.\fi

\M337. Here's a trivial subroutine that copies an edge structure. (Let's hope
that the given structure isn't too large.)

\Y\P\4\&{function}\1\  \37$\\{copy\_edges}(\|h:\\{pointer})$: \37\\{pointer};\6
\4\&{var} \37$\|p,\39\|r$: \37\\{pointer};\C{variables that traverse the given
structure}\6
$\\{hh},\39\\{pp},\39\\{qq},\39\\{rr},\39\\{ss}$: \37\\{pointer};\C{variables
that traverse the new structure}\2\6
\&{begin} \37$\\{hh}\K\\{get\_node}(\\{edge\_header\_size})$;\5
$\\{mem}[\\{hh}+1]\K\\{mem}[\|h+1]$;\5
$\\{mem}[\\{hh}+2]\K\\{mem}[\|h+2]$;\5
$\\{mem}[\\{hh}+3]\K\\{mem}[\|h+3]$;\5
$\\{mem}[\\{hh}+4]\K\\{mem}[\|h+4]$;\C{we've now copied \\{n\_min}, \\{n\_max},
	\\{m\_min}, \\{m\_max}, \\{m\_offset}, \\{last\_window}, and \\{last\_window%
\_time}}\6
$\\{n\_pos}(\\{hh})\K\\{n\_max}(\\{hh})+1$;\5
$\\{n\_rover}(\\{hh})\K\\{hh}$;\6
$\|p\K\\{link}(\|h)$;\5
$\\{qq}\K\\{hh}$;\6
\&{while} $\|p\I\|h$ \1\&{do}\6
\&{begin} \37$\\{pp}\K\\{get\_node}(\\{row\_header\_size})$;\5
$\\{link}(\\{qq})\K\\{pp}$;\5
$\\{knil}(\\{pp})\K\\{qq}$;\5
\X338:Copy the \\{sorted} and \\{unsorted} lists of \|p to \\{pp}\X;\6
$\|p\K\\{link}(\|p)$;\5
$\\{qq}\K\\{pp}$;\6
\&{end};\2\6
$\\{link}(\\{qq})\K\\{hh}$;\5
$\\{knil}(\\{hh})\K\\{qq}$;\5
$\\{copy\_edges}\K\\{hh}$;\6
\&{end};\par
\fi

\M338. \P$\X338:Copy the \\{sorted} and \\{unsorted} lists of \|p to \\{pp}\X%
\S$\6
$\|r\K\\{sorted}(\|p)$;\5
$\\{rr}\K\\{sorted\_loc}(\\{pp})$;\C{$\\{link}(\\{rr})=\\{sorted}(\\{pp})$}\6
\&{while} $\|r>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\\{ss}\K\\{get\_avail}$;\5
$\\{link}(\\{rr})\K\\{ss}$;\5
$\\{rr}\K\\{ss}$;\5
$\\{info}(\\{rr})\K\\{info}(\|r)$;\6
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
$\\{link}(\\{rr})\K\\{sentinel}$;\6
$\|r\K\\{unsorted}(\|p)$;\5
$\\{rr}\K\\{temp\_head}$;\6
\&{while} $\|r>\\{null1}$ \1\&{do}\6
\&{begin} \37$\\{ss}\K\\{get\_avail}$;\5
$\\{link}(\\{rr})\K\\{ss}$;\5
$\\{rr}\K\\{ss}$;\5
$\\{info}(\\{rr})\K\\{info}(\|r)$;\6
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
$\\{link}(\\{rr})\K\|r$;\5
$\\{unsorted}(\\{pp})\K\\{link}(\\{temp\_head})$\par
\U section~337.\fi

\M339. The \\{unsorted} edges of a row are merged into the \\{sorted} ones by
a subroutine called \\{sort\_edges}. It uses simple insertion sort,
followed by a merge, because the unsorted list is supposedly quite short.
However, the unsorted list is assumed to be nonempty.

\Y\P\4\&{procedure}\1\  \37$\\{sort\_edges}(\|h:\\{pointer})$;\C{\|h is a row
header}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|k: \37\\{halfword};\C{key register that we compare to $\\{info}(%
\|q)$}\6
$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\2\6
\&{begin} \37$\|r\K\\{unsorted}(\|h)$;\5
$\\{unsorted}(\|h)\K\\{null}$;\5
$\|p\K\\{link}(\|r)$;\5
$\\{link}(\|r)\K\\{sentinel}$;\5
$\\{link}(\\{temp\_head})\K\|r$;\6
\&{while} $\|p\L\\{null1}$ \1\&{do}\C{sort node \|p into the list that starts
at \\{temp\_head}}\6
\&{begin} \37$\|k\K\\{info}(\|p)$;\5
$\|q\K\\{temp\_head}$;\6
\1\&{repeat} \37$\|r\K\|q$;\5
$\|q\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|k\L\\{info}(\|q)$;\2\6
$\\{link}(\|r)\K\|p$;\5
$\|r\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\|q$;\5
$\|p\K\|r$;\6
\&{end};\2\6
\X340:Merge the \\{temp\_head} list into $\\{sorted}(\|h)$\X;\6
\&{end};\par
\fi

\M340. In this step we use the fact that $\\{sorted}(\|h)=\\{link}(\\{sorted%
\_loc}(\|h))$.

\Y\P$\4\X340:Merge the \\{temp\_head} list into $\\{sorted}(\|h)$\X\S$\6
\&{begin} \37$\|r\K\\{sorted\_loc}(\|h)$;\5
$\|q\K\\{link}(\|r)$;\5
$\|p\K\\{link}(\\{temp\_head})$;\6
\~ \1\&{loop}\ \&{begin} \37$\|k\K\\{info}(\|p)$;\6
\&{while} $\|k>\\{info}(\|q)$ \1\&{do}\6
\&{begin} \37$\|r\K\|q$;\5
$\|q\K\\{link}(\|r)$;\6
\&{end};\2\6
$\\{link}(\|r)\K\|p$;\5
$\|s\K\\{link}(\|r)$;\5
$\\{link}(\|p)\K\|q$;\6
\&{if} $\|s=\\{sentinel}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|r\K\|p$;\5
$\|p\K\|s$;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~339.\fi

\M341. The \\{cull\_edges} procedure ``optimizes'' an edge structure by making
all the pixel weights either 0 or~1. The weight will be~1 after the operation
if and only if it was $\G\\{w\_plus}$ or $\L\\{w\_minus}$ before, where \\{w%
\_plus} is
positive and \\{w\_minus} is negative. (In particular, zero-weight pixels
will remain of weight zero. This is fortunate, because there are infinitely
many of them.)

Rows that become all zero will remain in the structure; i.e., \\{n\_min} and
\\{n\_max} don't change.

\Y\P\4\&{procedure}\1\  \37$\\{cull\_edges}(\|h:\\{pointer};\,\35\\{w\_plus},%
\39\\{w\_minus}:\\{integer})$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list
manipulation}\6
\|w: \37\\{integer};\C{accumulated weight so far}\6
\|z: \37\\{integer};\C{a register for unpacking}\6
\|m: \37\\{integer};\C{the current column number, including \\{m\_offset}}\6
\\{ww}: \37\\{integer};\C{the new weight after culling}\6
$\\{prev\_m},\39\\{prev\_ww}$: \37\\{integer};\C{values of \|m and \\{ww}
before this column}\2\6
\&{begin} \37$\|p\K\\{link}(\|h)$;\6
\&{while} $\|p\I\|h$ \1\&{do}\6
\&{begin} \37\&{if} $\\{unsorted}(\|p)>\\{null1}$ \1\&{then}\5
$\\{sort\_edges}(\|p)$;\2\6
$\X342:Cull superfluous edge-weight entries from $\\{sorted}(\|p)$\X\|p\K%
\\{link}(\|p)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M342. The entire \\{sorted} list is return to available memory in this step;
a new list is built starting (temporarily) at \\{temp\_head}.

\Y\P$\4\X342:Cull superfluous edge-weight entries from $\\{sorted}(\|p)$\X\S$\6
$\|w\K0$;\5
$\|r\K\\{temp\_head}$;\5
$\\{prev\_m}\K-1$;\5
$\\{prev\_ww}\K0$;\5
$\|q\K\\{sorted}(\|p)$;\6
\&{while} $\|q>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\|z\K\\{ho}(\\{info}(\|q))$;\5
$\|m\K\|z\mathbin{\&{div}}8$;\5
$\|w\K\|w+(\|z\mathbin{\&{mod}}8)-\\{zero\_w}$;\6
\&{if} $\|m\I\\{prev\_m}$ \1\&{then}\5
\X343:Insert an edge-weight for edge \|m, if the new pixel weight has changed%
\X;\2\6
$\|s\K\\{link}(\|q)$;\5
$\\{free\_avail}(\|q)$;\5
$\|q\K\|s$;\6
\&{end};\2\6
$\\{link}(\|r)\K\\{sentinel}$;\5
$\\{sorted}(\|p)\K\\{link}(\\{temp\_head})$\par
\U section~341.\fi

\M343. \P$\X343:Insert an edge-weight for edge \|m, if the new pixel weight has
changed\X\S$\6
\&{begin} \37\&{if} $(\|w\G\\{w\_plus})\V(\|w\L\\{w\_minus})$ \1\&{then}\5
$\\{ww}\K1$\ \&{else} $\\{ww}\K0$;\2\6
\&{if} $\\{ww}\I\\{prev\_ww}$ \1\&{then}\6
\&{begin} \37$\|s\K\\{get\_avail}$;\5
$\\{link}(\|r)\K\|s$;\5
$\\{info}(\|s)\K8\ast\|m+\\{min\_halfword}+\\{zero\_w}+\\{ww}-\\{prev\_ww}$;\5
$\|r\K\|s$;\5
$\\{prev\_ww}\K\\{ww}$;\6
\&{end};\2\6
$\\{prev\_m}\K\|m$;\6
\&{end}\par
\U section~342.\fi

\M344. One way to put new edge weights into an edge structure is to use the
following routine, which simply draws a straight line from $(\\{x0},\\{y0})$ to
$(\\{x1},\\{y1})$. More precisely, it introduces weights for the edges of the
discrete path $\bigl(\round(t[x_0,x_1]),\round(t[y_0,y_1])\bigr)$,
as $t$ varies from 0 to~1.

The structure header is assumed to be \\{cur\_edges}; downward edge weights
will be \\{cur\_wt}, while upward ones will be $-\\{cur\_wt}$.

Of course, this subroutine will be called only in connection with others
that eventually draw a complete cycle, so that the sum of the edge weights
in each row will be zero whenever the row is displayed.

\Y\P\4\&{procedure}\1\  \37$\\{line\_edges}(\\{x0},\39\\{y0},\39\\{x1},\39%
\\{y1}:\\{scaled})$;\6
\4\&{label} \37$\\{done},\39\\{done1}$; \6
\4\&{var} \37$\\{m0},\39\\{n0},\39\\{m1},\39\\{n1},\39\|n$: \37\\{integer};%
\C{rounded and unscaled coordinates}\6
$\\{delx},\39\\{dely}$: \37\\{scaled};\C{the coordinate differences of the
line}\6
\\{yt}: \37\\{scaled};\C{smallest \|y coordinate that rounds the same as %
\\{y0}}\6
$\|p,\39$\1\6
\&{begin} \37$\\{n0}\K\\{round\_unscaled}(\\{y0})$;\5
$\\{n1}\K\\{round\_unscaled}(\\{y1})$;\6
\&{if} $\\{n0}\I\\{n1}$ \1\&{then}\6
\&{begin} \37$\\{m0}\K\\{round\_unscaled}(\\{x0})$;\5
$\\{m1}\K\\{round\_unscaled}(\\{x1})$;\5
$\\{delx}\K\\{x1}-\\{x0}$;\5
$\\{dely}\K\\{y1}-\\{y0}$;\5
$\\{yt}\K\\{n0}\ast\\{unity}-\\{half\_unit}$;\5
$\\{y0}\K\\{y0}-\\{yt}$;\5
$\\{y1}\K\\{y1}-\\{yt}$;\6
\&{if} $\\{n0}<\\{n1}$ \1\&{then}\5
\X345:Insert upward edges for a line\X\6
\4\&{else} \X346:Insert downward edges for a line\X;\2\6
$\\{n\_rover}(\\{cur\_edges})\K\|p$;\5
$\\{n\_pos}(\\{cur\_edges})\K\\{n1}+\\{zero\_field}$;\6
\&{end};\2\6
\&{end};\2\par
\fi

\M345. \P$\X345:Insert upward edges for a line\X\S$\6
\&{begin} \37$\\{decr}(\\{n1})$;\5
$\\{base}\K8\ast\\{m\_offset}(\\{cur\_edges})+\\{min\_halfword}+\\{zero\_w}-%
\\{cur\_wt}$;\6
\&{if} $\\{m0}\L\\{m1}$ \1\&{then}\5
$\\{edge\_prep}(\\{m0},\39\\{m1},\39\\{n0},\39\\{n1})$\ \&{else} $\\{edge%
\_prep}(\\{m1},\39\\{m0},\39\\{n0},\39\\{n1})$;\2\6
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
$\\{y0}\K\\{unity}-1-\\{y0}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|r\K\\{get\_avail}$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\\{info}(\|r)\K8\ast\\{round\_unscaled}(\\{x0}+\30\\{take\_fraction}(\\{delx},%
\39\\{make\_fraction}(\\{y0},\39\\{dely})))+\\{base}$;\5
$\\{y1}\K\\{y1}-\\{unity}$;\6
\&{if} $\\{y1}<\\{unity}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|p\K\\{link}(\|p)$;\5
$\\{y0}\K\\{y0}+\\{unity}$;\6
\&{end};\2\6
\4\\{done}: \37\&{end}\par
\U section~344.\fi

\M346. \P$\X346:Insert downward edges for a line\X\S$\6
\&{begin} \37$\\{decr}(\\{n0})$;\5
$\\{base}\K8\ast\\{m\_offset}(\\{cur\_edges})+\\{min\_halfword}+\\{zero\_w}+%
\\{cur\_wt}$;\6
\&{if} $\\{m0}\L\\{m1}$ \1\&{then}\5
$\\{edge\_prep}(\\{m0},\39\\{m1},\39\\{n0},\39\\{n1})$\ \&{else} $\\{edge%
\_prep}(\\{m1},\39\\{m0},\39\\{n0},\39\\{n1})$;\2\6
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
\~ \1\&{loop}\ \&{begin} \37$\|r\K\\{get\_avail}$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\\{info}(\|r)\K8\ast\\{round\_unscaled}(\\{x0}-\30\\{take\_fraction}(\\{delx},%
\39\\{make\_fraction}(\\{y0},\39\\{dely})))+\\{base}$;\5
$\\{y1}\K\\{y1}+\\{unity}$;\6
\&{if} $\\{y1}\G0$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\|p\K\\{knil}(\|p)$;\5
$\\{y0}\K\\{y0}+\\{unity}$;\6
\&{end};\2\6
\4\\{done1}: \37\&{end}\par
\U section~344.\fi

\M347. \P$\X347:Move to row \\{n0}, pointed to by \|p\X\S$\6
$\|n\K\\{n\_pos}(\\{cur\_edges})-\\{zero\_field}$;\5
$\|p\K\\{n\_rover}(\\{cur\_edges})$;\6
\&{if} $\|n<\\{n0}$ \1\&{then}\6
\1\&{repeat} \37$\\{incr}(\|n)$;\5
$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\|n=\\{n0}$\2\6
\4\&{else} \1\&{repeat} \37$\\{decr}(\|n)$;\5
$\|p\K\\{knil}(\|p)$;\6
\4\&{until}\5
$\|n=\\{n0}$\2\2\par
\U sections~345, 346, 349, 350, 351, and~352.\fi

\M348. \MF\ inserts most of its edges into edge structures via the
\\{move\_to\_edges} subroutine, which uses the data stored in the \\{move}
array
to specify a sequence of ``rook moves.'' The starting point $(\\{m0},\\{n0})$
and finishing point $(\\{m1},\\{n1})$ of these moves, as seen from the
standpoint
of the first octant, are supplied as parameters; the moves should, however,
be rotated into a given octant, supplied as a further parameter.

The rook moves themselves are defined as follows, from a \\{first\_octant}
point of view: ``Go right $\\{move}[\|k]$ steps, then go up one, for $0\L\|k<%
\\{n1}-\\{n0}$;
then go right $\\{move}[\\{n1}-\\{n0}]$ steps and stop.'' The sum of $%
\\{moves}[\|k]$
for $0\L\|k\L\\{n1}-\\{n0}$ will be equal to $\\{m1}-\\{m0}$.

As in the \\{line\_edges} routine, we use $+\\{cur\_wt}$ as the weight of
all downward edges and $-\\{cur\_wt}$ as the weight of all upward edges,
after the moves have been rotated to the proper octant direction.

There are two main cases to consider: \\{fast\_case} is for moves that
travel in the direction of octants 1, 4, 5, and~8, while \\{slow\_case}
is for moves that travel toward octants 2, 3, 6, and~7. The latter directions
are somewhat cumbersome because they generate more upward or downward edges;
a curve that travels horizontally doesn't produce any edges at all, but a
curve that travels vertically touches lots of rows.

\Y\P\D \37$\\{fast\_case\_up}=60$\C{for octants 1 and 4}\par
\P\D \37$\\{fast\_case\_down}=61$\C{for octants 5 and 8}\par
\P\D \37$\\{slow\_case\_up}=62$\C{for octants 2 and 3}\par
\P\D \37$\\{slow\_case\_down}=63$\C{for octants 6 and 7}\par
\Y\P\4\&{procedure}\1\  \37$\\{move\_to\_edges}(\\{m0},\39\\{n0},\39\\{m1},\39%
\\{n1}:\\{integer};\,\35\\{octant}:\\{small\_number})$;\6
\4\&{label} \37$\\{fast\_case\_up},\39\\{fast\_case\_down},\39\\{slow\_case%
\_up},\39\\{slow\_case\_down},\39\\{done}$;\6
\4\&{var} \37\\{delta}: \37$0\to\\{move\_size}$;\C{extent of \\{move} data}\6
\|k: \37$0\to\\{move\_size}$;\C{index into \\{move}}\6
$\|p,\39\|r$: \37\\{pointer};\C{list manipulation registers}\6
\\{dx}: \37\\{integer};\C{change in edge-weight \\{info} when \|x changes by 1}%
\6
\\{edge\_and\_weight}: \37\\{integer};\C{\\{info} to insert}\6
\|n: \37\\{integer};\C{number of consecutive vertical moves}\6
\\{n\_fin}: \37\\{integer};\C{the final row pointed to by \|p}\2\6
\&{begin} \37$\\{delta}\K\\{n1}-\\{n0}$;\6
\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37\&{begin} \37$\\{dx}\K8$;\5
\&{goto} \37\\{fast\_case\_up};\6
\&{end};\6
\4\\{second\_octant}: \37\&{begin} \37$\\{dx}\K8$;\5
\&{goto} \37\\{slow\_case\_up};\6
\&{end};\6
\4\\{third\_octant}: \37\&{begin} \37$\\{dx}\K-8$;\5
$\\{negate}(\\{n0})$;\5
\&{goto} \37\\{slow\_case\_up};\6
\&{end};\6
\4\\{fourth\_octant}: \37\&{begin} \37$\\{dx}\K-8$;\5
$\\{negate}(\\{m0})$;\5
\&{goto} \37\\{fast\_case\_up};\6
\&{end};\6
\4\\{fifth\_octant}: \37\&{begin} \37$\\{dx}\K-8$;\5
$\\{negate}(\\{m0})$;\5
\&{goto} \37\\{fast\_case\_down};\6
\&{end};\6
\4\\{sixth\_octant}: \37\&{begin} \37$\\{dx}\K-8$;\5
$\\{negate}(\\{n0})$;\5
\&{goto} \37\\{slow\_case\_down};\6
\&{end};\6
\4\\{seventh\_octant}: \37\&{begin} \37$\\{dx}\K8$;\5
\&{goto} \37\\{slow\_case\_down};\6
\&{end};\6
\4\\{eighth\_octant}: \37\&{begin} \37$\\{dx}\K8$;\5
\&{goto} \37\\{fast\_case\_down};\6
\&{end};\2\6
\&{end};\C{there are only eight octants}\6
\4\\{fast\_case\_up}: \37\X349:Add edges for first or fourth octants, then %
\&{goto} \\{done}\X;\6
\4\\{fast\_case\_down}: \37\X350:Add edges for fifth or eighth octants, then %
\&{goto} \\{done}\X;\6
\4\\{slow\_case\_up}: \37\X351:Add edges for second or third octants, then %
\&{goto} \\{done}\X;\6
\4\\{slow\_case\_down}: \37\X352:Add edges for sixth or seventh octants, then %
\&{goto} \\{done}\X;\6
\4\\{done}: \37$\\{n\_pos}(\\{cur\_edges})\K\\{n\_fin}+\\{zero\_field}$;\5
$\\{n\_rover}(\\{cur\_edges})\K\|p$;\6
\&{end};\par
\fi

\M349. \P$\X349:Add edges for first or fourth octants, then \&{goto} \\{done}\X%
\S$\6
\&{if} $\\{dx}>0$ \1\&{then}\5
$\\{edge\_prep}(\\{m0},\39\\{m1},\39\\{n0},\39\\{n1}-1)$\ \&{else} $\\{edge%
\_prep}(-\\{m1},\39\\{m0},\39\\{n0},\39\\{n1}-1)$;\2\6
$\\{n\_fin}\K\\{n1}$;\5
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
\&{if} $\\{delta}>0$ \1\&{then}\6
\&{begin} \37$\|k\K0$;\5
$\\{edge\_and\_weight}\K8\ast(\\{m0}+\\{m\_offset}(\\{cur\_edges}))+%
\\{halfword}+\\{zero\_w}-\\{cur\_wt}$;\6
\1\&{repeat} \37$\\{edge\_and\_weight}\K\\{edge\_and\_weight}+\\{dx}\ast%
\\{move}[\|k]$;\5
$\\{fast\_get\_avail}(\|r)$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{info}(\|r)\K\\{edge\_and\_weight}$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|k=\\{delta}$;\2\6
\&{end};\2\6
\&{goto} \37\\{done}\par
\U section~348.\fi

\M350. \P$\X350:Add edges for fifth or eighth octants, then \&{goto} \\{done}\X%
\S$\6
$\\{n0}\K-\\{n0}-1$;\6
\&{if} $\\{dx}>0$ \1\&{then}\5
$\\{edge\_prep}(\\{m0},\39\\{m1},\39-\\{n1},\39\\{n0})$\ \&{else} $\\{edge%
\_prep}(-\\{m1},\39\\{m0},\39-\\{n1},\39\\{n0})$;\2\6
$\\{n\_fin}\K-\\{n1}-1$;\5
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
\&{if} $\\{delta}>0$ \1\&{then}\6
\&{begin} \37$\|k\K0$;\5
$\\{edge\_and\_weight}\K8\ast(\\{m0}+\\{m\_offset}(\\{cur\_edges}))+%
\\{halfword}+\\{zero\_w}+\\{cur\_wt}$;\6
\1\&{repeat} \37$\\{edge\_and\_weight}\K\\{edge\_and\_weight}+\\{dx}\ast%
\\{move}[\|k]$;\5
$\\{fast\_get\_avail}(\|r)$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{info}(\|r)\K\\{edge\_and\_weight}$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\|p\K\\{knil}(\|p)$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|k=\\{delta}$;\2\6
\&{end};\2\6
\&{goto} \37\\{done}\par
\U section~348.\fi

\M351. \P$\X351:Add edges for second or third octants, then \&{goto} \\{done}\X%
\S$\6
$\\{edge\_and\_weight}\K8\ast(\\{n0}+\\{m\_offset}(\\{cur\_edges}))+%
\\{halfword}+\\{zero\_w}-\\{cur\_wt}$;\6
\&{if} $\\{dx}>0$ \1\&{then}\5
$\\{edge\_prep}(\\{n0},\39\\{n1},\39\\{m0},\39\\{m1}-1)$\ \&{else} $\\{edge%
\_prep}(-\\{n1},\39\\{n0},\39\\{m0},\39\\{m1}-1)$;\2\6
$\\{n0}\K\\{m0}$;\5
$\\{n\_fin}\K\\{m1}$;\5
$\|k\K0$;\5
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
\1\&{repeat} \37$\|n\K\\{moves}[\|k]$;\6
\&{while} $\|n>0$ \1\&{do}\6
\&{begin} \37$\\{fast\_get\_avail}(\|r)$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{info}(\|r)\K\\{edge\_and\_weight}$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{decr}(\|n)$;\6
\&{end};\2\6
$\\{edge\_and\_weight}\K\\{edge\_and\_weight}+\\{dx}$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|k>\\{delta}$;\2\6
\&{goto} \37\\{done}\par
\U section~348.\fi

\M352. \P$\X352:Add edges for sixth or seventh octants, then \&{goto} \\{done}%
\X\S$\6
$\\{edge\_and\_weight}\K8\ast(\\{n0}+\\{m\_offset}(\\{cur\_edges}))+%
\\{halfword}+\\{zero\_w}+\\{cur\_wt}$;\6
\&{if} $\\{dx}>0$ \1\&{then}\5
$\\{edge\_prep}(\\{n0},\39\\{n1},\39-\\{m1},\39-\\{m0}-1)$\ \&{else} $\\{edge%
\_prep}(-\\{n1},\39\\{n0},\39-\\{m1},\39-\\{m0}-1)$;\2\6
$\\{n0}\K-\\{m0}-1$;\5
$\\{n\_fin}\K-\\{m1}-1$;\5
$\|k\K0$;\5
\X347:Move to row \\{n0}, pointed to by \|p\X;\6
\1\&{repeat} \37$\|n\K\\{moves}[\|k]$;\6
\&{while} $\|n>0$ \1\&{do}\6
\&{begin} \37$\\{fast\_get\_avail}(\|r)$;\5
$\\{link}(\|r)\K\\{unsorted}(\|p)$;\5
$\\{info}(\|r)\K\\{edge\_and\_weight}$;\5
$\\{unsorted}(\|p)\K\|r$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{decr}(\|n)$;\6
\&{end};\2\6
$\\{edge\_and\_weight}\K\\{edge\_and\_weight}+\\{dx}$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|k>\\{delta}$;\2\6
\&{goto} \37\\{done}\par
\U section~348.\fi

\M353. All the hard work of building an edge structure is undone by the
following
subroutine. It returns \\{true} if at least one \\{unsorted} list was nonempty;
in such cases some of the data in the structure was never used.

\Y\P\4\&{function}\1\  \37$\\{toss\_edges}(\|h:\\{pointer})$: \37\\{boolean};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for list manipulation}\6
\\{data\_lost}: \37\\{boolean};\C{has some unsorted data been destroyed?}\2\6
\&{begin} \37$\|q\K\\{link}(\|h)$;\5
$\\{data\_lost}\K\\{false}$;\6
\&{while} $\|q\I\|h$ \1\&{do}\6
\&{begin} \37$\\{flush\_list}(\\{sorted}(\|q))$;\6
\&{if} $\\{unsorted}(\|q)>\\{null1}$ \1\&{then}\6
\&{begin} \37$\\{data\_lost}\K\\{true}$;\5
$\\{flush\_list}(\\{unsorted}(\|q))$;\6
\&{end};\2\6
$\|p\K\|q$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{free\_node}(\|p,\39\\{row\_node\_size})$;\6
\&{end};\2\6
$\\{free\_node}(\|h,\39\\{edge\_header\_size})$;\5
$\\{toss\_edges}\K\\{data\_lost}$;\6
\&{end};\par
\fi

\N354.  \[xx] Subdivision into octants.
When \MF\ digitizes a path, it reduces the problem to the special
case of paths that travel in ``first octant'' directions; i.e.,
each cubic $z(t)=x(t)+iy(t)$ being digitized will have the property
that $0\L y'(t)\L x'(t)$. This assumption makes digitizing simpler
and faster than if the direction of motion had to be tested repeatedly.

When $z(t)$ is cubic, $x'(t)$ and $y'(t)$ are quadratic, hence the four
polynomials $x'(t)$, $y'(t)$, $x'(t)-y'(t)$, and $x'(t)+y'(t)$ cross
through~0 at most twice each. If we subdivide the given cubic at these
places, we get at most nine subintervals in each of which
$x'(t)$, $y'(t)$, $x'(t)-y'(t)$, and $x'(t)+y'(t)$ all have a constant
sign. The curve can be transformed in each of these subintervals so that
it travels entirely in first octant directions, if we reflect $x\swap-x$,
$y\swap-y$, and/or $x\swap y$ as necessary. (Incidentally, it can be
shown that a cubic such that $x'(t)=16(2t-1)↑2+2(2t-1)-1$ and
$y'(t)=8(2t-1)↑2+4(2t-1)$ does indeed split into nine subintervals.)

\MF\ converts $z(t)=x(t)+iy(t)$ into a discrete curve that runs through
the points $\round\bigl(x(t)\bigr)+i\cdot\round\bigl(y(t)\bigr)$,
where $\round(x)=\lfloor x+{1\over2}\rfloor$. When $x$ is a \\{scaled}
value, the corresponding integer formula is $\round(x)=\lfloor(x+2↑{15})/
2↑{16}\rfloor$. The transformation $x\mapsto\bar x$ that changes the sign
of~$x$ should have the property that $\round(\bar x)=-\round(x)$, so that
curve points on the boundaries between octant shifts will round
consistently. It turns out that $\bar x=-x-1$ is the appropriate
mapping, for \\{scaled} integers; this is the ones' complement of~$x$.

For example, consider $z(t)=7+3t+i({5\over4}+t-t↑2)$. The derivative is
$z'(t)=3+i(1-2t)$; so this curve begins traveling in the direction of
the first octant, after which it heads into the eighth. \MF\ will subdivide
the unit interval into two parts by splitting it at $t={1\over2}$
(i.e., at the point where $y'(t)=0$). In the first subinterval, $z(t)$
runs from $7+{5\over4}i$ to $10+{3\over2}i$, which rounds to a
path from $7+i$ to $10+2i$. In the other subinterval, \MF\ converts
$z(t)$ to $\bar z(t)$ (which travels in first octant because the
$y$-coordinates have been complemented), and subsequently recovers
from this transformation by negating the $y$-coordinates of the digitized
curve obtained by rounding~$\bar z(t)$. If $z(t)$ were simply defined
by negating the $y$~components of~$z(t)$, it would start at $10-{3\over2}i$,
which would round to $10-i$ instead of $10-2i$; this would not match with
$10+2i$ when the $y$-coordinate is subsequently negated again. Therefore
$\bar z(t)$ is defined to be $7+3t+i(-{5\over4}-t+t↑2-\epsilon$,
where $\epsilon=2↑{-16}$; this $\epsilon$ is just the right amount to
guarantee consistent rounding across octant boundaries.

\Y\P\D \37$\\{comp}(\#)\S-\#-1$\C{ones' complement, used to negate unrounded
values}\par
\P\D \37$\\{complement}(\#)\S\#\K-\#-1$\C{replaces a variable by its ones'
complement}\par
\fi

\M355. The transformation that rotates coordinates so that first octant motion
can be assumed is defined by the \\{rotate} subroutine, which sets global
variables \\{cur\_x} and \\{cur\_y} to the values appropriate in a given
octant.
(Octants are encoded as they were in the arctangent subroutine.)

\Y\P\D \37$\\{set\_two\_tail}(\#)\S\\{cur\_y}\K\#$;\ \&{end} \par
\P\D $\\{set\_two}(\#)\S$ \6
\&{begin} \37$\\{cur\_x}\K\#$;\5
\\{set\_two\_tail}\par
\Y\P\4\&{procedure}\1\  \37$\\{rotate}(\|x,\39\|y:\\{scaled};\,\35\\{octant}:%
\\{small\_number})$;\2\6
\&{begin} \37\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37$\\{set\_two}(\|x)(\|y)$;\6
\4\\{second\_octant}: \37$\\{set\_two}(\|y)(\|x)$;\6
\4\\{third\_octant}: \37$\\{set\_two}(\|y)(\\{comp}(\|x))$;\6
\4\\{fourth\_octant}: \37$\\{set\_two}(\\{comp}(\|x))(\|y)$;\6
\4\\{fifth\_octant}: \37$\\{set\_two}(\\{comp}(\|x))(\\{comp}(\|y))$;\6
\4\\{sixth\_octant}: \37$\\{set\_two}(\\{comp}(\|y))(\\{comp}(\|x))$;\6
\4\\{seventh\_octant}: \37$\\{set\_two}(\\{comp}(\|y))(\|x)$;\6
\4\\{eighth\_octant}: \37$\\{set\_two}(\|x)(\\{comp}(\|y))$;\2\6
\&{end};\C{there are no other cases}\6
\&{end};\par
\fi

\M356. Conversely, the following subroutine sets \\{cur\_x} and
\\{cur\_y} to the original coordinate values of a point, given an octant
code and the point's coordinates $(\|x,\|y)$ after they have been mapped into
the first octant.

\Y\P\4\&{procedure}\1\  \37$\\{unrotate}(\|x,\39\|y:\\{scaled};\,\35\\{octant}:%
\\{small\_number})$;\par
\fi

\M357. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{cur\_x},\39\\{cur\_y}$: \37\\{scaled};\C{outputs of \\{rotate} and %
\\{unrotate}}\par
\fi

\M358. Here's a subroutine that's handy for subdivision: Given a
quadratic polynomial $B(a,b,c;t)$, the \\{crossing\_point} function
returns the unique \\{fraction} value \|t between 0 and~1 at which
$B(a,b,c;t)$ changes from positive to negative, or returns
$\|t=\\{fraction\_one}+1$ if no such value exists. If $\|a<0$ (so that
$B(a,b,c;t)$
is already negative), \\{crossing\_point} returns zero.

\Y\P\D \37$\\{no\_crossing}\S$\1\6
\&{begin} \37$\\{crossing\_point}\K\\{fraction\_one}+1$;\5
\&{return};\6
\&{end}\2\par
\P\D \37$\\{zero\_crossing}\S$\1\6
\&{begin} \37$\\{crossing\_point}\K0$;\5
\&{return};\6
\&{end}\2\par
\Y\P\4\&{function}\1\  \37$\\{crossing\_point}(\|a,\39\|b,\39\|c:\\{integer})$:
\37\\{fraction};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|d: \37\\{integer};\C{recursive counter}\6
$\|x,\39\\{xx},\39\\{x0},\39\\{x1},\39\\{x2}$: \37\\{integer};\C{temporary
registers for bisection}\2\6
\&{begin} \37\&{if} $\|a<0$ \1\&{then}\5
\\{zero\_crossing};\2\6
\&{if} $\|c\G0$ \1\&{then}\6
\&{begin} \37\&{if} $\|b\G0$ \1\&{then}\5
\\{no\_crossing};\2\6
\&{if} $\|a=0$ \1\&{then}\5
\\{zero\_crossing};\2\6
\&{end}\6
\4\&{else} \&{if} $\|a=0$ \1\&{then}\6
\&{if} $\|b\L0$ \1\&{then}\5
\\{zero\_crossing};\2\2\2\6
\X359:Use bisection to find the crossing point, if one exists\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M359. The general bisection method is quite simple when $n=2$, hence
\\{crossing\_point} does not take much time. At each stage in the
recursion we have a subinterval defined by \|l and~\|j such that
$B(a,b,c;2↑{-l}(j+t))=B(x_0,x_1,x_2;t)$, and we want to zero in on
the subinterval where $x_0\G0$ and $\min(x_1,x_2)<0$.

It is convenient for purposes of calculation to combine the values
of \|l and~\|j in a single variable $d=2↑l+j$, because the operation
of bisection then corresponds simply to doubling $d$ and possibly
adding~1. Furthermore it proves to be convenient to modify
our previous conventions for bisection slightly, maintaining the
variables $X_0=2↑lx_0$, $X_1=2↑l(x_0-x_1)$, and $X_2=2↑l(x_1-x_2)$.
With these variables the conditions $x_0≥0$ and $\min(x_1,x_2)<0$ are
equivalent to $\max(X_1+X_1+X_2)>X_0\G0$.

No arithmetic overflow will occur if $a<2↑{30}$, $\vert a-b\vert<2↑{29}$,
and $\vert b-c\vert<2↑{29}$.

\Y\P$\4\X359:Use bisection to find the crossing point, if one exists\X\S$\6
$\|d\K1$;\5
$\\{x0}\K\|a$;\5
$\\{x1}\K\|a-\|b$;\5
$\\{x2}\K\|b-\|c$;\6
\1\&{repeat} \37$\\{x0}\K\\{x0}+\\{x0}$;\5
$\|x\K\\{half}(\\{x1}+\\{x2})$;\6
\&{if} $\\{x1}>\\{x0}$ \1\&{then}\6
\&{begin} \37$\\{x2}\K\|x$;\5
$\|d\K\|d+\|d$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{xx}\K\\{x1}+\|x$;\6
\&{if} $\\{xx}>\\{x0}$ \1\&{then}\6
\&{begin} \37$\\{x2}\K\|x$;\5
$\|d\K\|d+\|d$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{x0}\K\\{x0}-\\{xx}$;\6
\&{if} $\|x\L\\{x0}$ \1\&{then}\6
\&{if} $\|x+\\{x2}\L\\{x0}$ \1\&{then}\5
\\{no\_crossing};\2\2\6
$\\{x1}\K\|x$;\5
$\|d\K\|d+\|d+1$;\6
\&{end};\2\6
\&{end};\2\6
\4\&{until}\5
$\|d\G\\{fraction\_one}$;\2\6
$\\{crossing\_point}\K\|d-\\{fraction\_one}$\par
\U section~358.\fi

\M360. Octant subdivision is applied only to cycles, i.e., to closed paths;
it follows that the cycle passes through all eight octants before
coming back to its starting place.

A ``cycle spec'' is a data structure that contains specifications of
cubic curves and octant mappings for the cycle that has been subdivided
into segments belonging to single octants. It is composed entirely of
knot nodes, similar to those in the representation of paths; but the
\\{explicit} type indications have been replaced by positive numbers
that give further information. Additional \\{endpoint} data is also
inserted at the octant boundaries.

Recall that a cubic polynomial is represented by four control points
that appear in adjacent nodes \|p and~\|q of a knot list. The \|x~coordinates
are $\\{x\_coord}(\|p)$, $\\{right\_x}(\|p)$, $\\{left\_x}(\|q)$, and $\\{x%
\_coord}(\|q)$; the
\|y~coordinates are similar. We shall call this ``the cubic following~\|p''
or ``the cubic between \|p and~\|q'' or ``the cubic preceding~\|q.''

Cycle specs are circular lists of cubic curves mixed with octant
boundaries. Like cubics, the octant boundaries are represented in
consecutive knot nodes \|p and~\|q. In such cases $\\{right\_type}(\|p)=\\{left%
\_type}(\|q)=\\{endpoint}$, and the fields $\\{right\_x}(\|p)$, $\\{right\_y}(%
\|p)$,
$\\{left\_x}(\|q)$, and $\\{left\_y}(\|q)$ are replaced by other fields called
$\\{right\_octant}(\|p)$, $\\{right\_transition}(\|p)$, $\\{left\_octant}(%
\|q)$, and
$\\{left\_transition}(\|q)$, respectively. For example, when the curve
direction
moves from the third octant to the fourth octant, the nodes say
$\\{right\_octant}(\|p)=\\{third\_octant}$, $\\{left\_octant}(\|q)=\\{fourth%
\_octant}$,
and $\\{right\_transition}(\|p)=\\{left\_transition}(\|q)=\\{diagonal}$. A %
\\{diagonal}
transition occurs when moving between octants 1~\&~2, 3~\&~4, 5~\&~6, or
7~\&~8; an \\{axis} transition occurs when moving between octants 8~\&~1,
2~\&~3, 4~\&~5, 6~\&~7. (Such transition information is redundant
but convenient.) Fields $\\{x\_coord}(\|p)$ and $\\{y\_coord}(\|p)$ will
contain
coordinates of the transition point after rotation from third octant
to first octant; i.e., if the true coordinates are $(x,y)$, the
coordinates $(y,\bar x)$ will appear in node~\|p. Similarly, a fourth-octant
transformation will have been applied after the transition, so
we will have $\\{x\_coord}(\|q)=\hbox{$\bar x$}$ and $\\{y\_coord}(\|q)=\|y$.

The cubic between \|p and \|q will contain positive numbers in the
fields $\\{right\_type}(\|p)$ and $\\{left\_type}(\|q)$; this makes cubics
distinguishable from octant boundaries, because $\\{endpoint}=0$.
The value of $\\{right\_type}(\|p)$ will be the current octant code,
during the time that cycle specs are being constructed; it will
refer later to a pen offset position, if the envelope of a cycle is
being computed. A cubic that comes from some subinterval of the $k$th
step in the original cyclic path will have $\\{left\_type}(\|q)=\|k$.

\Y\P\D \37$\\{right\_octant}\S\\{right\_x}$\C{the octant code before a
transition}\par
\P\D \37$\\{left\_octant}\S\\{left\_x}$\C{the octant after a transition}\par
\P\D \37$\\{right\_transition}\S\\{right\_y}$\C{the type of transition}\par
\P\D \37$\\{left\_transition}\S\\{left\_y}$\C{ditto, either \\{axis} or %
\\{diagonal}}\par
\P\D \37$\\{axis}=0$\C{a transition across the $x'$- or $y'$-axis}\par
\P\D \37$\\{diagonal}=1$\C{a transition where $y'=\pm x'$}\par
\fi

\M361. Here's a routine that prints a cycle spec in symbolic form,
so that it is possible to see what subdivision has been made.
The point coordinates are converted back from \MF's internal ``rotated''
form to the external ``true'' form. The parameter~\|h should point to
a knot just after the beginning of an octant boundary for the
first octant.

\Y\P\4\&{procedure}\1\  \37$\\{print\_spec}(\|h:\\{pointer},\39\|s:\\{str%
\_number})$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for list traversal}\6
\\{octant}: \37\\{small\_number};\C{the current octant code}\2\6
\&{begin} \37$\\{print\_diagnostic}(\.{"Cycle\ spec"},\39\|s)$;\5
$\|p\K\|h$;\5
\\{print\_ln};\5
$\\{print\_two}(\\{x\_coord}(\|h),\39\\{y\_coord}(\|h))$;\5
$\\{print}(\.{"\ \%\ beginning\ in\ the\ first\ octant"})$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|p)$;\5
\X362:Print the cubic or the octant boundary between \|p and \|q\X;\6
$\|p\K\|q$;\6
\4\&{until}\5
$\|p=\|h$;\2\6
$\\{print\_nl}(\.{"\ \&\ cycle"})$;\5
$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\par
\fi

\M362. \P$\X362:Print the cubic or the octant boundary between \|p and \|q\X\S$%
\6
\&{if} $\\{right\_type}(\|p)\I\\{endpoint}$ \1\&{then}\5
\X363:Print the cubic between \|p and \|q\X\6
\4\&{else} \&{begin} \37$\\{print\_nl}(\.{"\%\ entering\ the\ "})$;\5
$\\{octant}\K\\{left\_octant}(\|q)$;\6
\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37$\\{print}(\.{"first"})$;\6
\4\\{second\_octant}: \37$\\{print}(\.{"second"})$;\6
\4\\{third\_octant}: \37$\\{print}(\.{"third"})$;\6
\4\\{fourth\_octant}: \37$\\{print}(\.{"fourth"})$;\6
\4\\{fifth\_octant}: \37$\\{print}(\.{"fifth"})$;\6
\4\\{sixth\_octant}: \37$\\{print}(\.{"sixth"})$;\6
\4\\{seventh\_octant}: \37$\\{print}(\.{"seventh"})$;\6
\4\\{eighth\_octant}: \37$\\{print}(\.{"eighth"})$;\2\6
\&{end};\C{there ain't no more cases}\6
$\\{print}(\.{"\ octant"})$;\6
\&{end}\2\par
\U section~361.\fi

\M363. \P\D \37$\\{print\_two\_true}(\#)\S\\{unrotate}(\#,\39\\{octant})$;\5
$\\{print\_two}(\\{cur\_x},\39\\{cur\_y})$\par
\Y\P$\4\X363:Print the cubic between \|p and \|q\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{"\ ..controls\ "})$;\5
$\\{print\_two\_true}(\\{right\_x}(\|p),\39\\{right\_y}(\|p))$;\5
$\\{print}(\.{"\ and\ "})$;\5
$\\{print\_two\_true}(\\{left\_x}(\|q),\39\\{left\_y}(\|q))$;\5
$\\{print}(\.{"\ ..\ "})$;\5
$\\{print\_two\_true}(\\{x\_coord}(\|q),\39\\{y\_coord}(\|q))$;\5
$\\{print}(\.{"\ \%\ segment\ "})$;\5
$\\{print\_int}(\\{left\_type}(\|q))$;\6
$\\{print\_char}(\.{"["})$;\5
$\\{print}(\\{right\_type}(\|p))$;\5
$\\{print\_char}(\.{"]"})$;\6
\&{end}\par
\U section~362.\fi

\M364. The \\{make\_spec} routine is what subdivides paths into octants:
Given a pointer \|h to a cyclic path, \\{make\_spec} mungs the path data
and returns a pointer to the corresponding cyclic spec.
All ``dead'' cubics (i.e., cubics that don't move at all from
their starting points) have been removed from the result.

The idea of \\{make\_spec} is fairly simple: Each cubic is first
subdivided, if necessary, into pieces belonging to single octants;
then the octant boundaries are inserted. But some of the details of
this transformation are not quite obvious.

The result spec will have all scaled \|x and \|y coordinates at most
$2↑{28}-half_unit-1-safety_margin$ in absolute value.  The pointer that is
returned will start in the first octant, as required by \\{print\_spec}.

\Y\P\X372:Declare subroutines needed by \\{make\_spec}\X\6
\4\&{function}\1\  \37$\\{make\_spec}(\|h:\\{pointer};\,\35\\{safety\_margin}:%
\\{scaled})$: \37\\{pointer};\C{converts a path to a cycle spec}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s,\39\\{pp},\39\\{qq}$: \37\\{pointer};%
\C{for traversing the lists}\6
\|k: \37\\{integer};\C{serial number of path segment}\6
\\{chopped}: \37\\{boolean};\C{have we truncate any of the data?}\6
\\{max\_allowed}: \37\\{scaled};\C{coordinates must be at most this big}\6
\X369:Other local variables for \\{make\_spec}\X\2\6
\&{begin} \37\&{if} $\\{internal}[\\{tracing\_specs}]>0$ \1\&{then}\5
$\\{print\_path}(\|h,\39\.{",\ before\ subdivision\ into\ octants"})$;\2\6
$\\{max\_allowed}\K\\{fraction\_one}-\\{half\_unit}-1-\\{safety\_margin}$;\5
\X366:Truncate the values of all coordinates that are too large, and stamp
serial numbers in each \\{left\_type} field\X;\6
\X367:Subdivide each cubic into octants\X;\6
\X384:Remove dead cubics\X;\6
\X388:Insert octant boundaries and compute the winding number\X;\6
\&{while} $(\\{left\_type}(\|h)\I\\{endpoint})\V(\\{left\_octant}(\|h)\I%
\\{first\_octant})$ \1\&{do}\5
$\|h\K\\{link}(\|h)$;\2\6
\&{if} $\\{internal}[\\{tracing\_specs}]>0$ \1\&{then}\5
$\\{print\_spec}(\|h,\39\.{",\ after\ subdivision"})$;\2\6
$\\{make\_spec}\K\|h$;\6
\&{end};\par
\fi

\M365. The \\{make\_spec} routine also has an interesting side effect: It sets
the global variable \\{winding\_number} to the number of times the tangent
vector of the given cyclic path winds around the origin, multiplied by~8.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{winding\_number}: \37\\{integer};\C{an output of \\{make\_spec}}\par
\fi

\M366. First we do a simple preprocessing step. The serial numbers inserted
here will propagate to all descendants of cubics that are split into
subintervals.

\Y\P\D \37$\\{procrustes}(\#)\S$\1\6
\&{if} $\\{abs}(\#)>\\{max\_allowed}$ \1\&{then}\6
\&{begin} \37$\\{chopped}\K\\{true}$;\6
\&{if} $\#>0$ \1\&{then}\5
$\#\K\\{max\_allowed}$\ \&{else} $\#\K-\\{max\_allowed}$;\2\6
\&{end}\2\2\par
\Y\P$\4\X366:Truncate the values of all coordinates that are too large, and
stamp serial numbers in each \\{left\_type} field\X\S$\6
$\|p\K\|h$;\5
$\|k\K1$;\5
$\\{chopped}\K\\{false}$;\6
\1\&{repeat} \37$\\{procrustes}(\\{left\_x}(\|p))$;\5
$\\{procrustes}(\\{left\_y}(\|p))$;\5
$\\{procrustes}(\\{x\_coord}(\|p))$;\5
$\\{procrustes}(\\{y\_coord}(\|p))$;\5
$\\{procrustes}(\\{right\_x}(\|p))$;\5
$\\{procrustes}(\\{right\_y}(\|p))$;\6
$\|p\K\\{link}(\|p)$;\5
$\\{left\_type}(\|p)\K\|k$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|p=\|h$;\2\6
\&{if} $\\{chopped}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Curve\ out\ of\ range"})$;\5
$\\{help4}(\.{"At\ least\ one\ of\ the\ coordinates\ in\ the\ path\ I\'m\ about%
\ to"})$\6
$(\.{"digitize\ was\ really\ huge\ (potentially\ bigger\ than\ 4095)."})$\6
$(\.{"So\ I\'ve\ cut\ it\ back\ to\ the\ maximum\ size."})$\6
$(\.{"The\ results\ will\ probably\ be\ pretty\ wild."})$;\5
\\{error};\6
\&{end}\2\par
\U section~364.\fi

\M367. The subdivision process proceeds by first swapping $x\swap-x$, if
necessary, to ensure that $x'\G0$; then swapping $y\swap-y$, if necessary,
to ensure that $y'\G0$; and finally swapping $x\swap y$, if necessary,
to ensure that $x'\G y'$.

Recall that the octant codes have been defined in such a way that, for
example, $\\{third\_octant}=\\{first\_octant}+\\{negate\_x}+\\{swap\_x\_y}$.
The program
uses the fact that $\\{negate\_x}<\\{negate\_y}<\\{swap\_x\_y}$ to handle
``double
negation'': If \|c is an octant code that possibly involves \\{negate\_x}
and/or \\{negate\_y}, but not \\{swap\_x\_y}, then negating~\|y changes~\|c
either to $\|c+\\{negate\_y}$ or $\|c-\\{negate\_y}$, depending on whether
$\|c\L\\{negate\_y}$ or $\|c>\\{negate\_y}$. Octant codes are always positive.

\Y\P$\4\X367:Subdivide each cubic into octants\X\S$\6
$\|p\K\|h$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|p)$;\5
\X368:Subdivide the cubic between \|p and \|q so that the results travel toward
the right halfplane\X;\6
\X375:Subdivide all cubics between \|p and \|q so that the results travel
toward the first quadrant\X;\6
\X379:Subdivide all cubics between \|p and \|q so that the results travel
toward the first octant\X;\6
$\|p\K\|q$;\6
\4\&{until}\5
$\|p=\|h$\2\par
\U section~364.\fi

\M368. All three subdivision processes are similar, so it's possible to
get the general idea by studying the first one (which is the simplest).
The calculation makes use of the fact that the derivatives of
Bernstein polynomials satisfy
$B'(z_0,z_1,\ldots,z_n;t)=nB(z_1-z_0,\ldots,z_n-z_{n-1};t)$.

At the beginning of this step, $\\{right\_type}(\|p)=\\{explicit}$; we should
set $\\{right\_type}(\|p)\K\\{first\_octant}$. However, no assignment is made,
because $\\{explicit}=\\{first\_octant}$. The author apologizes for using
trickery here; it is really hard to do redundant computations
just for the sake of purity.

\Y\P$\4\X368:Subdivide the cubic between \|p and \|q so that the results travel
toward the right halfplane\X\S$\6
$\\{del1}\K\\{right\_x}(\|p)-\\{x\_coord}(\|p)$;\5
$\\{del2}\K\\{left\_x}(\|q)-\\{right\_x}(\|p)$;\5
$\\{del3}\K\\{x\_coord}(\|q)-\\{left\_x}(\|q)$;\5
\X370:Scale up \\{del1}, \\{del2}, and \\{del3} for greater accuracy; also set %
\\{del} to the first nonzero element of $(\\{del1},\\{del2},\\{del3})$\X;\6
\&{if} $\\{del}\I0$ \1\&{then}\C{they weren't all zero}\6
\&{begin} \37\&{if} $\\{del}<0$ \1\&{then}\5
\X371:Complement the \|x coordinates of the cubic between \|p and~\|q\X;\2\6
$\|t\K\\{crossing\_point}(\\{del1},\39\\{del2},\39\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X373:Subdivide the cubic with respect to $x'$, possibly twice\X;\2\6
\&{end}\2\par
\U section~367.\fi

\M369. \P$\X369:Other local variables for \\{make\_spec}\X\S$\6
\4$\\{del1},\39\\{del2},\39\\{del3},\39\\{del},\39\\{dmax}$: \37\\{scaled};%
\C{proportional to the control 	points of a quadratic derived from a cubic}\6
\4\|t: \37\\{fraction};\C{where a quadratic crosses zero}\par
\A section~391.
\U section~364.\fi

\M370. If $\\{del1}=\\{del2}=\\{del3}=0$, it's impossible to obey the title of
this
section. We just set $\\{del}=0$ in that case.

\Y\P$\4\X370:Scale up \\{del1}, \\{del2}, and \\{del3} for greater accuracy;
also set \\{del} to the first nonzero element of $(\\{del1},\\{del2},\\{del3})$%
\X\S$\6
\&{if} $\\{del1}\I0$ \1\&{then}\5
$\\{del}\K\\{del1}$\6
\4\&{else} \&{if} $\\{del2}\I0$ \1\&{then}\5
$\\{del}\K\\{del2}$\6
\4\&{else} $\\{del}\K\\{del3}$;\2\2\6
\&{if} $\\{del}\I0$ \1\&{then}\6
\&{begin} \37$\\{dmax}\K\\{abs}(\\{del1})$;\6
\&{if} $\\{abs}(\\{del2})>\\{dmax}$ \1\&{then}\5
$\\{dmax}\K\\{abs}(\\{del2})$;\2\6
\&{if} $\\{abs}(\\{del3})>\\{dmax}$ \1\&{then}\5
$\\{dmax}\K\\{abs}(\\{del3})$;\2\6
\&{while} $\\{dmax}<\\{fraction\_half}$ \1\&{do}\6
\&{begin} \37$\\{dmax}\K\\{dmax}+\\{dmax}$;\5
$\\{del1}\K\\{del1}+\\{del1}$;\5
$\\{del2}\K\\{del2}+\\{del2}$;\5
$\\{del3}\K\\{del3}+\\{del3}$;\6
\&{end};\2\6
\&{end}\2\par
\U sections~368, 375, and~379.\fi

\M371. During the subdivision phase of \\{make\_spec}, the \\{x\_coord} and %
\\{y\_coord}
fields of node~\|q will not be transformed to agree with the octant
stated in $\\{right\_type}(\|p)$; they remain consistent with $\\{right\_type}(%
\|q)$.

\Y\P$\4\X371:Complement the \|x coordinates of the cubic between \|p and~\|q\X%
\S$\6
\&{begin} \37$\\{complement}(\\{x\_coord}(\|p))$;\5
$\\{complement}(\\{right\_x}(\|p))$;\5
$\\{complement}(\\{left\_x}(\|q))$;\6
$\\{negate}(\\{del1})$;\5
$\\{negate}(\\{del2})$;\5
$\\{negate}(\\{del3})$;\6
$\\{right\_type}(\|p)\K\\{first\_octant}+\\{negate\_x}$;\6
\&{end}\par
\U section~368.\fi

\M372. When a cubic is split at a \\{fraction} value \|t, we obtain two cubics
whose B\'ezier control points are obtained by a generalization of the
bisection process: The formula
`$z_k↑{(j+1)}={1\over2}(z_k↑{(j)}+z\k↑{(j)}$' becomes
`$z_k↑{(j+1)}=t[z_k↑{(j)},z\k↑{(j)}]$'.

\Y\P\D \37$\\{t\_of\_the\_way\_tail}(\#)\S\#,\39\|t\={)}$\par
\P\D \37$\\{t\_of\_the\_way}(\#)\S\#-\\{take\_fraction}\={(}\#-\\{t\_of\_the%
\_way\_tail}$\par
\Y\P$\4\X372:Declare subroutines needed by \\{make\_spec}\X\S$\6
\4\&{procedure}\1\  \37$\\{split\_cubic}(\|p:\\{pointer};\,\35\|t:%
\\{fraction})$;\C{splits the cubic after \|p}\6
\4\&{var} \37\|v: \37\\{scaled};\C{an intermediate value}\6
$\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\|r\K\\{get\_node}(\\{knot\_size})$;\5
$\\{link}(\|p)\K\|r$;\5
$\\{link}(\|r)\K\|q$;\6
$\\{unrotate}(\\{x\_coord}(\|q),\39\\{y\_coord}(\|q),\39\\{right\_type}(\|q))$;%
\5
$\\{rotate}(\\{cur\_x},\39\\{cur\_y},\39\\{right\_type}(\|p))$;\C{now all
coordinates are consistent}\6
$\\{left\_type}(\|r)\K\\{left\_type}(\|q)$;\5
$\\{right\_type}(\|r)\K\\{right\_type}(\|p)$;\7
$\|v\K\\{t\_of\_the\_way}(\\{right\_x}(\|p))(\\{left\_x}(\|q))$;\5
$\\{right\_x}(\|p)\K\\{t\_of\_the\_way}(\\{x\_coord}(\|p))(\\{right\_x}(\|p))$;%
\5
$\\{left\_x}(\|q)\K\\{t\_of\_the\_way}(\\{left\_x}(\|q))(\\{cur\_x})$;\5
$\\{left\_x}(\|r)\K\\{t\_of\_the\_way}(\\{right\_x}(\|p))(\|v)$;\5
$\\{right\_x}(\|r)\K\\{t\_of\_the\_way}(\|v)(\\{left\_x}(\|q))$;\5
$\\{x\_coord}(\|r)\K\\{t\_of\_the\_way}(\\{left\_x}(\|r))(\\{right\_x}(\|r))$;\7
$\|v\K\\{t\_of\_the\_way}(\\{right\_y}(\|p))(\\{left\_y}(\|q))$;\5
$\\{right\_y}(\|p)\K\\{t\_of\_the\_way}(\\{y\_coord}(\|p))(\\{right\_y}(\|p))$;%
\5
$\\{left\_y}(\|q)\K\\{t\_of\_the\_way}(\\{left\_y}(\|q))(\\{cur\_y})$;\5
$\\{left\_y}(\|r)\K\\{t\_of\_the\_way}(\\{right\_y}(\|p))(\|v)$;\5
$\\{right\_y}(\|r)\K\\{t\_of\_the\_way}(\|v)(\\{left\_y}(\|q))$;\5
$\\{y\_coord}(\|r)\K\\{t\_of\_the\_way}(\\{left\_y}(\|r))(\\{right\_y}(\|r))$;\6
\&{end};\par
\A sections~385 and~389.
\U section~364.\fi

\M373. Since $x'(t)$ is a quadratic equation, it can cross through zero
at~most twice. When it does cross zero, we make doubly sure that the
derivative is really zero after splitting, in case rounding errors have
caused the split cubic to have an apparently nonzero derivative.

\Y\P$\4\X373:Subdivide the cubic with respect to $x'$, possibly twice\X\S$\6
\&{begin} \37$\\{split\_cubic}(\|p,\39\|t)$;\5
$\|r\K\\{link}(\|p)$;\6
\&{if} $\\{right\_type}(\|r)>\\{negate\_x}$ \1\&{then}\5
$\\{right\_type}(\|r)\K\\{first\_octant}$\6
\4\&{else} $\\{right\_type}(\|r)\K\\{first\_octant}+\\{negate\_x}$;\2\6
$\\{left\_x}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{complement}(\\{x\_coord}(\|r))$;\5
$\\{right\_x}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{complement}(\\{left\_x}(\|q))$;\6
$\\{del2}\K\\{t\_of\_the\_way}(\\{del2})(\\{del3})$;\C{now $0,\\{del2},%
\\{del3}$ represent $x'$ on the remaining interval}\6
\&{if} $\\{del2}>0$ \1\&{then}\5
$\\{del2}\K0$;\2\6
$\|t\K\\{crossing\_point}(0,\39-\\{del2},\39-\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X374:Subdivide the cubic a second time with respect to $x'$\X;\2\6
\&{end}\par
\U section~368.\fi

\M374. \P$\X374:Subdivide the cubic a second time with respect to $x'$\X\S$\6
\&{begin} \37$\\{split\_cubic}(\|r,\39\|t)$;\5
$\|r\K\\{link}(\|r)$;\6
$\\{right\_type}(\|r)\K\\{right\_type}(\|p)$;\5
$\\{left\_x}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{complement}(\\{x\_coord}(\|r))$;\5
$\\{right\_x}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{complement}(\\{left\_x}(\|q))$;\6
\&{end}\par
\U section~373.\fi

\M375. The process of subdivision with respect to $y'$ is like that with
respect
to~$x'$, with the slight additional complication that two or three cubics
might now appear between \|p and~\|q.

\Y\P$\4\X375:Subdivide all cubics between \|p and \|q so that the results
travel toward the first quadrant\X\S$\6
$\\{pp}\K\|p$;\6
\1\&{repeat} \37$\\{qq}\K\\{link}(\\{pp})$;\5
$\\{del1}\K\\{right\_y}(\\{pp})-\\{y\_coord}(\\{pp})$;\5
$\\{del2}\K\\{left\_y}(\\{qq})-\\{right\_y}(\\{pp})$;\5
$\\{del3}\K\\{y\_coord}(\\{qq})-\\{left\_y}(\\{qq})$;\5
\X370:Scale up \\{del1}, \\{del2}, and \\{del3} for greater accuracy; also set %
\\{del} to the first nonzero element of $(\\{del1},\\{del2},\\{del3})$\X;\6
\&{if} $\\{del}\I0$ \1\&{then}\C{they weren't all zero}\6
\&{begin} \37\&{if} $\\{del}<0$ \1\&{then}\5
\X376:Complement the \|y coordinates of the cubic between \\{pp} and~\\{qq}\X;%
\2\6
$\|t\K\\{crossing\_point}(\\{del1},\39\\{del2},\39\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X377:Subdivide the cubic with respect to $y'$, possibly twice\X;\2\6
\&{end};\2\6
$\\{pp}\K\\{qq}$;\6
\4\&{until}\5
$\\{pp}=\|q$\2\par
\U section~367.\fi

\M376. \P$\X376:Complement the \|y coordinates of the cubic between \\{pp} and~%
\\{qq}\X\S$\6
\&{begin} \37$\\{complement}(\\{y\_coord}(\\{pp}))$;\5
$\\{complement}(\\{right\_y}(\\{pp}))$;\5
$\\{complement}(\\{left\_y}(\\{qq}))$;\6
$\\{negate}(\\{del1})$;\5
$\\{negate}(\\{del2})$;\5
$\\{negate}(\\{del3})$;\6
$\\{right\_type}(\\{pp})\K\\{right\_type}(\\{pp})+\\{negate\_y}$;\6
\&{end}\par
\U section~375.\fi

\M377. \P$\X377:Subdivide the cubic with respect to $y'$, possibly twice\X\S$\6
\&{begin} \37$\\{split\_cubic}(\\{pp},\39\|t)$;\5
$\|r\K\\{link}(\\{pp})$;\6
\&{if} $\\{right\_type}(\|r)>\\{negate\_y}$ \1\&{then}\5
$\\{right\_type}(\|r)\K\\{right\_type}(\|r)-\\{negate\_y}$\6
\4\&{else} $\\{right\_type}(\|r)\K\\{right\_type}(\|r)+\\{negate\_y}$;\2\6
$\\{left\_y}(\|r)\K\\{y\_coord}(\|r)$;\5
$\\{complement}(\\{y\_coord}(\|r))$;\5
$\\{right\_y}(\|r)\K\\{y\_coord}(\|r)$;\5
$\\{complement}(\\{left\_y}(\\{qq}))$;\6
$\\{del2}\K\\{t\_of\_the\_way}(\\{del2})(\\{del3})$;\C{now $0,\\{del2},%
\\{del3}$ represent $y'$ on the remaining interval}\6
\&{if} $\\{del2}>0$ \1\&{then}\5
$\\{del2}\K0$;\2\6
$\|t\K\\{crossing\_point}(0,\39-\\{del2},\39-\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X378:Subdivide the cubic a second time with respect to $y'$\X;\2\6
\&{end}\par
\U section~375.\fi

\M378. \P$\X378:Subdivide the cubic a second time with respect to $y'$\X\S$\6
\&{begin} \37$\\{split\_cubic}(\|r,\39\|t)$;\5
$\|r\K\\{link}(\|r)$;\6
$\\{right\_type}(\|r)\K\\{right\_type}(\\{pp})$;\5
$\\{left\_y}(\|r)\K\\{y\_coord}(\|r)$;\5
$\\{complement}(\\{y\_coord}(\|r))$;\5
$\\{right\_y}(\|r)\K\\{y\_coord}(\|r)$;\5
$\\{complement}(\\{left\_y}(\\{qq}))$;\6
\&{end}\par
\U section~377.\fi

\M379. Finally, the process of subdividing to make $x'\G y'$ is like
subdividing
with respect to~$y'$, with the slight additional complication that the
\\{x\_coord} and/or \\{y\_coord} fields in node \\{qq} may need to be
complemented
at the beginning.

\Y\P$\4\X379:Subdivide all cubics between \|p and \|q so that the results
travel toward the first octant\X\S$\6
$\\{pp}\K\|p$;\6
\1\&{repeat} \37$\\{qq}\K\\{link}(\\{pp})$;\5
\X380:Set up $(\\{del1},\\{del2},\\{del3})$ to represent $x'-y'$\X;\6
\X370:Scale up \\{del1}, \\{del2}, and \\{del3} for greater accuracy; also set %
\\{del} to the first nonzero element of $(\\{del1},\\{del2},\\{del3})$\X;\6
\&{if} $\\{del}\I0$ \1\&{then}\C{they weren't all zero}\6
\&{begin} \37\&{if} $\\{del}<0$ \1\&{then}\5
\X381:Swap the \|x and \|y coordinates of the cubic between \\{pp} and~\\{qq}%
\X;\2\6
$\|t\K\\{crossing\_point}(\\{del1},\39\\{del2},\39\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X382:Subdivide the cubic with respect to $x'-y'$, possibly twice\X;\2\6
\&{end};\2\6
$\\{pp}\K\\{qq}$;\6
\4\&{until}\5
$\\{pp}=\|q$\2\par
\U section~367.\fi

\M380. \P$\X380:Set up $(\\{del1},\\{del2},\\{del3})$ to represent $x'-y'$\X\S$%
\6
$\\{unrotate}(\\{x\_coord}(\\{qq}),\39\\{y\_coord}(\\{qq}),\39\\{right\_type}(%
\\{qq}))$;\5
$\\{rotate}(\\{cur\_x},\39\\{cur\_y},\39\\{right\_type}(\\{pp}))$;\5
$\\{del1}\K\\{right\_x}(\\{pp})-\\{right\_y}(\\{pp})$;\5
$\\{del2}\K\\{left\_x}(\\{qq})-\\{left\_y}(\\{qq})$;\6
$\\{del3}\K\\{cur\_x}-\\{cur\_y}-\\{del2}$;\5
$\\{del2}\K\\{del2}-\\{del1}$;\5
$\\{del1}\K\\{del1}-(\\{x\_coord}(\\{pp})-\\{y\_coord}(\\{pp}))$\par
\U section~379.\fi

\M381. \P$\X381:Swap the \|x and \|y coordinates of the cubic between \\{pp}
and~\\{qq}\X\S$\6
\&{begin} \37$\\{del}\K\\{y\_coord}(\\{pp})$;\5
$\\{y\_coord}(\\{pp})\K\\{x\_coord}(\\{pp})$;\5
$\\{x\_coord}(\\{pp})\K\\{del}$;\5
$\\{del}\K\\{right\_y}(\\{pp})$;\5
$\\{right\_y}(\\{pp})\K\\{right\_x}(\\{pp})$;\5
$\\{right\_x}(\\{pp})\K\\{del}$;\5
$\\{del}\K\\{left\_y}(\\{qq})$;\5
$\\{left\_y}(\\{qq})\K\\{left\_x}(\\{qq})$;\5
$\\{left\_x}(\\{qq})\K\\{del}$;\5
$\\{negate}(\\{del1})$;\5
$\\{negate}(\\{del2})$;\5
$\\{negate}(\\{del3})$;\6
$\\{right\_type}(\\{pp})\K\\{right\_type}(\\{pp})+\\{swap\_x\_y}$;\6
\&{end}\par
\U section~379.\fi

\M382. \P$\X382:Subdivide the cubic with respect to $x'-y'$, possibly twice\X%
\S$\6
\&{begin} \37$\\{split\_cubic}(\\{pp},\39\|t)$;\5
$\|r\K\\{link}(\\{pp})$;\6
\&{if} $\\{right\_type}(\|r)>\\{swap\_x\_y}$ \1\&{then}\5
$\\{right\_type}(\|r)\K\\{right\_type}(\|r)-\\{swap\_x\_y}$\6
\4\&{else} $\\{right\_type}(\|r)\K\\{right\_type}(\|r)+\\{swap\_x\_y}$;\2\6
$\\{left\_y}(\|r)\K\\{y\_coord}(\|r)-(\\{x\_coord}(\|r)-\\{left\_x}(\|r))$;\5
$\\{del}\K\\{y\_coord}(\|r)$;\5
$\\{y\_coord}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{x\_coord}(\|r)\K\\{del}$;\5
$\\{right\_y}(\|r)\K\\{right\_x}(\|r)$;\5
$\\{right\_x}(\|r)\K\\{x\_coord}(\|r)+\\{right\_y}(\|r)-\\{y\_coord}(\|r)$;\5
$\\{del}\K\\{left\_y}(\\{qq})$;\5
$\\{left\_y}(\\{qq})\K\\{left\_x}(\\{qq})$;\5
$\\{left\_x}(\\{qq})\K\\{del}$;\5
$\\{del2}\K\\{t\_of\_the\_way}(\\{del2})(\\{del3})$;\C{now $0,\\{del2},%
\\{del3}$ represent $x'-y'$ on the remaining interval}\6
\&{if} $\\{del2}>0$ \1\&{then}\5
$\\{del2}\K0$;\2\6
$\|t\K\\{crossing\_point}(0,\39-\\{del2},\39-\\{del3})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X383:Subdivide the cubic a second time with respect to $x'-y'$\X;\2\6
\&{end}\par
\U section~379.\fi

\M383. \P$\X383:Subdivide the cubic a second time with respect to $x'-y'$\X\S$\6
\&{begin} \37$\\{split\_cubic}(\|r,\39\|t)$;\5
$\|r\K\\{link}(\|r)$;\6
$\\{left\_y}(\|r)\K\\{y\_coord}(\|r)-(\\{x\_coord}(\|r)-\\{left\_x}(\|r))$;\5
$\\{del}\K\\{y\_coord}(\|r)$;\5
$\\{y\_coord}(\|r)\K\\{x\_coord}(\|r)$;\5
$\\{x\_coord}(\|r)\K\\{del}$;\5
$\\{right\_y}(\|r)\K\\{right\_x}(\|r)$;\5
$\\{right\_x}(\|r)\K\\{x\_coord}(\|r)+\\{right\_y}(\|r)-\\{y\_coord}(\|r)$;\5
$\\{del}\K\\{left\_y}(\\{qq})$;\5
$\\{left\_y}(\\{qq})\K\\{left\_x}(\\{qq})$;\5
$\\{left\_x}(\\{qq})\K\\{del}$;\6
\&{end}\par
\U section~382.\fi

\M384. If the cycle reduces to a single point, we are left with a
single dead cubic that will not be removed---at least not~yet.

\Y\P$\4\X384:Remove dead cubics\X\S$\6
$\|p\K\|h$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|p)$;\6
\&{if} $(\|p\I\|h)\V(\|q\I\|h)$ \1\&{then}\6
\&{begin} \37\&{if} $\\{x\_coord}(\|p)=\\{right\_x}(\|p)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{right\_y}(\|p)$ \1\&{then}\6
\&{if} $\\{x\_coord}(\|p)=\\{left\_x}(\|q)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{left\_y}(\|q)$ \1\&{then}\6
\&{begin} \37$\\{unrotate}(\\{x\_coord}(\|q),\39\\{y\_coord}(\|q),\39\\{right%
\_type}(\|q))$;\5
$\\{rotate}(\\{cur\_x},\39\\{cur\_y},\39\\{right\_type}(\|p))$;\6
\&{if} $\\{x\_coord}(\|p)=\\{cur\_x}$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{cur\_y}$ \1\&{then}\6
\&{begin} \37$\\{remove\_cubic}(\|p)$;\6
\&{if} $\|q=\|h$ \1\&{then}\5
$\|h\K\|p$;\2\6
$\|q\K\|p$;\6
\&{end};\2\2\6
\&{end};\2\2\2\2\6
\&{end};\2\6
$\|p\K\|q$;\6
\4\&{until}\5
$\|p=\|h$;\2\par
\U section~364.\fi

\M385. \P$\X372:Declare subroutines needed by \\{make\_spec}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{remove\_cubic}(\|p:\\{pointer})$;\C{removes the
cubic following~\|p}\6
\4\&{var} \37\|q: \37\\{pointer};\C{the node that disappears}\2\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\\{right\_type}(\|p)\K\\{right\_type}(\|q)$;\5
$\\{link}(\|p)\K\\{link}(\|q)$;\6
$\\{x\_coord}(\|p)\K\\{x\_coord}(\|q)$;\5
$\\{y\_coord}(\|p)\K\\{y\_coord}(\|q)$;\6
$\\{right\_x}(\|p)\K\\{right\_x}(\|q)$;\5
$\\{right\_y}(\|p)\K\\{right\_y}(\|q)$;\6
$\\{free\_node}(\|q,\39\\{knot\_size})$;\6
\&{end};\par
\fi

\M386. Finally we come to the last steps of \\{make\_spec}, when boundary nodes
are inserted between cubics that move in different octants. The main
complication remaining arises from consecutive cubics whose octants
are not adjacent; we should insert more than one octant boundary
at such sharp turns, so that the envelop-forming routine will work.

For this purpose, conversion tables between numerical and Gray codes for
octants are desirable.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{octant\_number}: \37\&{array} $[\\{first\_octant}\to\\{sixth\_octant}]$ \1%
\&{of}\5
$1\to8$;\2\6
\4\\{octant\_code}: \37\&{array} $[1\to8]$ \1\&{of}\5
$\\{first\_octant}\to\\{sixth\_octant}$;\2\par
\fi

\M387. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{octant\_code}[1]\K\\{first\_octant}$;\5
$\\{octant\_code}[2]\K\\{second\_octant}$;\5
$\\{octant\_code}[3]\K\\{third\_octant}$;\5
$\\{octant\_code}[4]\K\\{fourth\_octant}$;\5
$\\{octant\_code}[5]\K\\{fifth\_octant}$;\5
$\\{octant\_code}[6]\K\\{sixth\_octant}$;\5
$\\{octant\_code}[7]\K\\{seventh\_octant}$;\5
$\\{octant\_code}[8]\K\\{eighth\_octant}$;\6
\&{for} $\|k\K1\mathrel{\&{to}}8$ \1\&{do}\5
$\\{octant\_number}[\\{octant\_code}[\|k]]\K\|k$;\2\par
\fi

\M388. The main loop for boundary insertion deals with three consecutive
nodes $\|p,\|q,\|r$.

\Y\P$\4\X388:Insert octant boundaries and compute the winding number\X\S$\6
$\\{winding\_number}\K0$;\5
$\|p\K\|h$;\5
$\|q\K\\{link}(\|p)$;\6
\1\&{repeat} \37$\|r\K\\{link}(\|q)$;\6
\&{if} $(\\{right\_type}(\|p)\I\\{right\_type}(\|q))\V(\|q=\|r)$ \1\&{then}\5
\X390:Insert one or more octant boundary nodes just before~\|q\X;\2\6
$\|p\K\|q$;\5
$\|q\K\|r$;\6
\4\&{until}\5
$\|p=\|h$;\2\par
\U section~364.\fi

\M389. The \\{new\_boundary} subroutine comes in handy at this point. It
inserts
a new boundary node just after a given node \|p, using a givn octant code
to transform the new node's coordinates. The ``transition'' fields are
not computed here.

\Y\P$\4\X372:Declare subroutines needed by \\{make\_spec}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{new\_boundary}(\|p:\\{pointer};\,\35\\{octant}:%
\\{small\_number})$;\6
\4\&{var} \37$\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\C{we assume that $\\{right\_type}(\|q)\I%
\\{endpoint}$}\6
$\|r\K\\{get\_node}(\\{knot\_size})$;\5
$\\{link}(\|r)\K\|q$;\5
$\\{link}(\|p)\K\|r$;\5
$\\{left\_type}(\|r)\K\\{left\_type}(\|q)$;\C{but possibly $\\{left\_type}(%
\|q)=\\{endpoint}$}\6
$\\{left\_x}(\|r)\K\\{left\_x}(\|q)$;\5
$\\{left\_y}(\|r)\K\\{left\_y}(\|q)$;\5
$\\{right\_type}(\|r)\K\\{endpoint}$;\5
$\\{left\_type}(\|q)\K\\{endpoint}$;\5
$\\{right\_octant}(\|r)\K\\{octant}$;\5
$\\{left\_octant}(\|q)\K\\{right\_type}(\|q)$;\5
$\\{unrotate}(\\{x\_coord}(\|q),\39\\{y\_coord}(\|q),\39\\{right\_type}(\|q))$;%
\5
$\\{rotate}(\\{cur\_x},\39\\{cur\_y},\39\\{octant})$;\5
$\\{x\_coord}(\|r)\K\\{cur\_x}$;\5
$\\{y\_coord}(\|r)\K\\{cur\_y}$;\6
\&{end};\par
\fi

\M390. The case $\|q=\|r$ occurs if and only if $\|p=\|q=\|r=\|h$, when we want
to turn
$360↑\circ$ in eight steps and then remove a solitary dead cubic.

\Y\P$\4\X390:Insert one or more octant boundary nodes just before~\|q\X\S$\6
\&{begin} \37$\\{new\_boundary}(\|p,\39\\{right\_type}(\|p))$;\5
$\|s\K\\{link}(\|p)$;\5
$\\{o1}\K\\{octant\_number}[\\{right\_type}(\|p)]$;\5
$\\{o2}\K\\{octant\_number}[\\{right\_type}(\|q)]$;\6
\&{case} $\\{o2}-\\{o1}$ \1\&{of}\6
\4$1,\39-7,\397,\39-1$: \37\&{goto} \37\\{done};\6
\4$0,\392,\39-6$: \37$\\{clockwise}\K\\{false}$;\6
\4$3,\39-5,\394,\39-4,\395,\39-3$: \37\X392:Decide whether or not to go
clockwise\X;\6
\4$6,\39-2$: \37$\\{clockwise}\K\\{true}$;\2\6
\&{end};\C{there are no other cases}\6
\X394:Insert additional boundary nodes, then \&{goto} \\{done}\X;\6
\4\\{done}: \37\&{if} $\|q=\|r$ \1\&{then}\6
\&{begin} \37$\|q\K\\{link}(\|q)$;\5
$\|r\K\|q$;\5
$\|h\K\|q$;\5
$\|p\K\|q$;\5
$\\{remove\_cubic}(\|s)$;\6
\&{end};\2\6
\X395:Fix up the transition fields and adjust the winding number\X;\6
\&{end}\par
\U section~388.\fi

\M391. \P$\X369:Other local variables for \\{make\_spec}\X\mathrel{+}\S$\6
\4$\\{o1},\39\\{o2}$: \37\\{small\_number};\C{octant numbers}\6
\4\\{clockwise}: \37\\{boolean};\C{should we turn clockwise?}\6
\4$\\{dx1},\39\\{dy1},\39\\{dx2},\39\\{dy2}$: \37\\{integer};\C{directions of
travel at a cusp}\par
\fi

\M392. A tricky question arises when a path jumps four octants. We want the
direction of turning to be counterclockwise if the curve has changed
direction by $180↑\circ$, or by something so close to $180↑\circ$ that
the difference is probably due to rounding errors; otherwise we want to
turn through an angle of less than $180↑\circ$. This decision needs to
be made even when a curve seems to have jumped only three octants, since
a curve may approach direction $(-1,0)$ from the fourth octant, then
it might leave from direction $(+1,0)$ into the first.

The following code solves the problem by analyzing the incoming
direction $(\\{dx1},\\{dy1})$ and the outgoing direction $(\\{dx2},\\{dy2})$.

\Y\P$\4\X392:Decide whether or not to go clockwise\X\S$\6
\&{begin} \37\X393:Compute the incoming and outgoing directions\X;\6
$\\{unrotate}(\\{dx1},\39\\{dy1},\39\\{right\_type}(\|p))$;\5
$\\{del}\K\\{pyth\_add}(\\{cur\_x},\39\\{cur\_y})$;\6
$\\{dx1}\K\\{make\_fraction}(\\{cur\_x},\39\\{del})$;\5
$\\{dx2}\K\\{make\_fraction}(\\{cur\_y},\39\\{del})$;\C{$\cos\theta_1$ and $%
\sin\theta_1$}\6
$\\{unrotate}(\\{dx2},\39\\{dy2},\39\\{right\_type}(\|p))$;\5
$\\{del}\K\\{pyth\_add}(\\{cur\_x},\39\\{cur\_y})$;\6
$\\{dx2}\K\\{make\_fraction}(\\{cur\_x},\39\\{del})$;\5
$\\{dx2}\K\\{make\_fraction}(\\{cur\_y},\39\\{del})$;\C{$\cos\theta_2$ and $%
\sin\theta_2$}\6
$\\{del}\K\\{take\_fraction}(\\{dx1},\39\\{dy2})-\\{take\_fraction}(\\{dx2},\39%
\\{dy1})$;\C{$\sin(\theta_2-\theta_1)$}\6
\&{if} $\\{del}<-1143$ \1\&{then}\5
$\\{clockwise}\K\\{true}$\C{$2↑{16}\cdot\sin 1↑\circ\approx1143.761$}\6
\4\&{else} $\\{clockwise}\K\\{false}$;\2\6
\&{end}\par
\U section~390.\fi

\M393. \P$\X393:Compute the incoming and outgoing directions\X\S$\6
$\\{dx1}\K\\{x\_coord}(\|s)-\\{left\_x}(\|s)$;\5
$\\{dy1}\K\\{y\_coord}(\|s)-\\{left\_y}(\|s)$;\6
\&{if} $\\{dx1}=0$ \1\&{then}\6
\&{if} $\\{dy1}=0$ \1\&{then}\6
\&{begin} \37$\\{dx1}\K\\{x\_coord}(\|s)-\\{right\_x}(\|p)$;\5
$\\{dy1}\K\\{y\_coord}(\|s)-\\{right\_y}(\|p)$;\6
\&{if} $\\{dx1}=0$ \1\&{then}\6
\&{if} $\\{dy1}=0$ \1\&{then}\6
\&{begin} \37$\\{dx1}\K\\{x\_coord}(\|s)-\\{x\_coord}(\|p)$;\5
$\\{dy1}\K\\{y\_coord}(\|s)-\\{y\_coord}(\|p)$;\6
\&{end};\C{and they {\sl can't} both be zero}\2\2\6
\&{end};\2\2\6
$\\{dmax}\K\\{abs}(\\{dx1})$;\ \&{if} $\\{abs}(\\{dy1})>\\{dmax}$ \1\&{then}\5
$\\{dmax}\K\\{abs}(\\{dy1})$;\2\6
\&{while} $\\{dmax}<\\{fraction\_one}$ \1\&{do}\6
\&{begin} \37$\\{dmax}\K\\{dmax}+\\{dmax}$;\5
$\\{dx1}\K\\{dx1}+\\{dx1}$;\5
$\\{dy1}\K\\{dy1}+\\{dy1}$;\6
\&{end};\2\6
$\\{dx2}\K\\{right\_x}(\|q)-\\{x\_coord}(\|q)$;\5
$\\{dy2}\K\\{right\_y}(\|q)-\\{y\_coord}(\|q)$;\6
\&{if} $\\{dx2}=0$ \1\&{then}\6
\&{if} $\\{dy2}=0$ \1\&{then}\6
\&{begin} \37$\\{dx2}\K\\{left\_x}(\|r)-\\{x\_coord}(\|q)$;\5
$\\{dy2}\K\\{left\_y}(\|r)-\\{y\_coord}(\|q)$;\6
\&{if} $\\{dx2}=0$ \1\&{then}\6
\&{if} $\\{dy2}=0$ \1\&{then}\6
\&{begin} \37$\\{unrotate}(\\{x\_coord}(\|r),\39\\{y\_coord}(\|r),\39\\{right%
\_type}(\|r))$;\5
$\\{rotate}(\\{cur\_x},\39\\{cur\_y},\39\\{right\_type}(\|q))$;\5
$\\{dx2}\K\\{cur\_x}-\\{x\_coord}(\|q)$;\5
$\\{dy2}\K\\{cur\_y}-\\{y\_coord}(\|q)$;\6
\&{end};\C{and they {\sl can't} both be zero}\2\2\6
\&{end};\2\2\6
$\\{dmax}\K\\{abs}(\\{dx2})$;\ \&{if} $\\{abs}(\\{dy2})>\\{dmax}$ \1\&{then}\5
$\\{dmax}\K\\{abs}(\\{dy2})$;\2\6
\&{while} $\\{dmax}<\\{fraction\_one}$ \1\&{do}\6
\&{begin} \37$\\{dmax}\K\\{dmax}+\\{dmax}$;\5
$\\{dx2}\K\\{dx2}+\\{dx2}$;\5
$\\{dy2}\K\\{dy2}+\\{dy2}$;\6
\&{end}\2\par
\U section~392.\fi

\M394. \P$\X394:Insert additional boundary nodes, then \&{goto} \\{done}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{clockwise}$ \1\&{then}\6
\&{if} $\\{o1}=1$ \1\&{then}\5
$\\{o1}\K8$\ \&{else} $\\{decr}(\\{o1})$\2\6
\4\&{else} \&{if} $\\{o1}=8$ \1\&{then}\5
$\\{o1}\K1$\ \&{else} $\\{incr}(\\{o1})$;\2\2\6
\&{if} $\\{o1}=\\{o2}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{new\_boundary}(\|s,\39\\{octant\_code}[\\{o1}])$;\5
$\|s\K\\{link}(\|s)$;\5
$\\{left\_octant}(\|s)\K\\{right\_octant}(\|s)$;\6
\&{end}\2\par
\U section~390.\fi

\M395. Now it remains to insert the redundant information into the \\{left%
\_transition}
and \\{right\_transition} fields between adjacent octants, in the octant
boundary nodes that have just been inserted between $\\{link}(\|p)$ and~\|q.
The winding number is easily computed from these transitions.

\Y\P$\4\X395:Fix up the transition fields and adjust the winding number\X\S$\6
$\|p\K\\{link}(\|p)$;\6
\1\&{repeat} \37$\|s\K\\{link}(\|p)$;\5
$\\{o1}\K\\{octant\_number}[\\{right\_octant}(\|p)]$;\5
$\\{o2}\K\\{octant\_number}[\\{left\_octant}(\|s)]$;\6
\&{if} $\\{abs}(\\{o1}-\\{o2})=1$ \1\&{then}\6
\&{begin} \37$\\{winding\_number}\K\\{winding\_number}+\\{o2}-\\{o1}$;\6
\&{if} $\\{o2}<\\{o1}$ \1\&{then}\5
$\\{o2}\K\\{o1}$;\2\6
\&{if} $\\{odd}(\\{o2})$ \1\&{then}\5
$\\{right\_transition}(\|p)\K\\{axis}$\6
\4\&{else} $\\{right\_transition}(\|p)\K\\{diagonal}$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{o1}=8$ \1\&{then}\5
$\\{incr}(\\{winding\_number})$\ \&{else} $\\{decr}(\\{winding\_number})$;\2\6
$\\{right\_transition}(\|p)\K\\{axis}$;\6
\&{end};\2\6
$\\{left\_transition}(\|s)\K\\{right\_transition}(\|p)$;\5
$\|p\K\|s$;\6
\4\&{until}\5
$\|p=\|q$\2\par
\U section~390.\fi

\N396.  \[xx] Filling a contour.
Given the low-level machinery for making moves and for transforming a
cyclic path into a cycle spec, we need two more routines before the
computer is able to fill a digitized path: There must be a high-level
routine that walks through the cycle spec and controls the overall
process; and there must be a really low-level routine that takes the
\\{move} data and records it in a pixel-oriented data structure.
We shall tackle the high-level routine first, since it involves
interesting transformations that have some influence on the design
of the pixel data structures.

\fi

\M397. Our overall goal is to plot the integer points $\bigl(\round(x(t)),
\round(y(t))\bigr)$ and to connect them by rook moves, assuming that
$\round(x(t))$ and $\round(y(t))$ don't jump simultaneously from
one integer to another as $t$~varies; these rook moves will be the edge
of the contour that will be filled. We have reduced this problem to the
case of curves that travel in first octant directions, i.e., curves
such that $0\L y'(t)\L x'(t)$, by transforming the original coordinates.

\def\xtilde{{\tilde x}} \def\ytilde{{\tilde y}}
Another transformation makes the problem still simpler. We shall say that
we are working with {\sl skewed coordinates\/} when $(x,y)$ has been
replaced by $(\xtilde,\ytilde)=(x-y,y+{1\over2})$. When a curve travels
in first octant directions, the corresponding curve with skewed
coordinates travels in first {\sl quadrant\/} directions; the latter
condition is symmetric in $x$ and~$y$, so it has advantages for the
design of algorithms. Furthermore, we can determine the
rounded unskewed path $\bigl(\round(x(t)),\round(y(t))\bigr)$ from the
truncated skewed path $\bigl(\lfloor\xtilde(t)\rfloor,\lfloor\ytilde(t)\rfloor
\bigr)$ and information about the initial and final endpoints. If the
unrounded and unskewed
path begins at $(x_0,y_0)$ and ends at $(x_1,y_1)$, it's possible to
prove (by induction on the length of truncated skewed path) that the
rounded unskewed path is obtained by the following construction:

\yskip\textindent{1)} Start at $\bigl(\round(x_0),\round(y_0)\bigr)$.

\yskip\textindent{2)} If $(x_0+{1\over2}\bmod1\G(y_0+{1\over2}\bmod1$,
move one step right.

\yskip\textindent{3)} Whenever the path
$\bigl(\lfloor\xtilde(t)\rfloor,\lfloor\ytilde(t)\rfloor\bigr)$
takes an upward step (i.e., when
$\lfloor\xtilde(t+\epsilon)\rfloor=\lfloor\xtilde(t)\rfloor$ and
$\lfloor\ytilde(t+\epsilon)\rfloor=\lfloor\ytilde(t)\rfloor+1$),
move one step up and then one step right.

\yskip\textindent{4)} Whenever the path
$\bigl(\lfloor\xtilde(t)\rfloor,\lfloor\ytilde(t)\rfloor\bigr)$
takes a rightward step (i.e., when
$\lfloor\xtilde(t+\epsilon)\rfloor=\lfloor\xtilde(t)\rfloor+1$ and
$\lfloor\ytilde(t+\epsilon)\rfloor=\lfloor\ytilde(t)\rfloor$),
move one step right.

\yskip\textindent{5)} Finally, if
$(x_1+{1\over2}\bmod1\G(y_1+{1\over2}\bmod1$, move one step left (thereby
cancelling the previous move, which was one step right). You will now be
at the point $\bigl(\round(x_1),\round(y_1)\bigr)$.

\fi

\M398. We obtain better looking output if the underlying curve $z(t)$ is
in a ``good'' position with respect to the raster when its direction
of motion changes from one octant to another. Here ``good'' means that
the curve is not near points where rounding causes an abrupt transition.
For example, when the curve is travelling horizontally, it is desirable
to have $y(t)$ near an integer; if $y(t)$ is close to an integer
plus~$1\over2$ in such cases, the curve will either look too flat or
it will have a tiny bump. By contrast, the value of $x(t)$ is not important
near horizontal tangents, since the curve is moving through lots of
$x$ values at such times. We want $x(t)$ to be nearly an integer when
the curve is traveling vertically, but we have already rotated such
curves so that only first octant directions are present; hence the
case of vertical tangents is covered by the horizontal ones. There is,
however, another case that can readily be improved: When the curve is
traveling at a $45↑\circ$ angle, the constant
skewed coordinate $\xtilde=x(t)-y(t)$ should be nearly an integer
plus~$1\over2$; then $\lfloor\xtilde(t)\rfloor$ is not near a dangerous
transition point.

\def\xbreve{{\breve x}} \def\ybreve{{\breve y}}
\MF\ makes small adjustments to the path so that ``good'' positions
almost always occur at the octant transitions. The endpoints
$(x_0,y_0)$ and $(x_1,y_1)$ are mapped to the nearest possible good
values $(\xbreve_0,\ybreve_0)$ and $(\xbreve_1,\ybreve_1)$ subject
to the condition that $\round(\xbreve_k)=\round(x_k)$ and
$\round(\ybreve_k)=\round(y_k)$---i.e., such that the endpoints still
round to the same lattice points. Then the curve is adjusted slightly
so that the actual skewed coordinates are defined by the formulas
$$\displaylines{\xtilde=\lambda(x-y)+\alpha,\qquad
\ytilde=\mu y+\beta;\cr
\textstyle \xtilde_0=\xbreve_0-\ybreve_0,\quad
\ytilde_0=\ybreve_0+{1\over2};\qquad
\xtilde_1=\xbreve_1-\ybreve_1,\quad
\ytilde_1=\ybreve_1+{1\over2}.\cr}$$
This mapping preserves horizontal and $45↑\circ$ tangents, and it moves
the curve to good points when those critical tangents occur.

Anomalous situations can arise in which the values of $\lambda$ or~$\mu$
are negative or ridiculously large; in such cases we simply forget
about mapping to good endpoints, and we take $\lambda=\mu=1$,
$\alpha=0$, $\beta={1\over2}$.

\fi

\M399. The \\{skew} procedure performs the transformation $(x,y)\mapsto
(\xtilde,\ytilde)$ on all $(x,y)$ data in the cubics between given
pointers $\|p\I\|q$. The desired values of $(\xtilde_0,\ytilde_0)$ and
$(\xtilde_1,\ytilde_1)$ are supplied as parameters;

\Y\P\4\&{procedure}\1\  \37$\\{skew}(\|p,\39\|q:\\{pointer};\,\35\\{xx0},\39%
\\{yy0},\39\\{xx1},\39\\{yy1}:\\{scaled})$;\6
\4\&{var} \37$\\{lambda\_num},\39\\{lambda\_denom},\39\\{mu\_num},\39\\{mu%
\_denom},\39\\{alpha},\39\\{beta}$: \37\\{scaled};\C{registers for intermediate
results}\6
$\\{lambda},\39\\{mu}$: \37\\{fraction};\C{the multipliers}\2\6
\&{begin} \37\X400:Compute the coefficients \\{lambda}, \\{mu}, \\{alpha}, and %
\\{beta}\X;\6
$\\{x\_coord}(\|p)\K\\{xx0}$;\5
$\\{y\_coord}(\|p)\K\\{yy0}$;\6
\1\&{repeat} \37$\\{right\_x}(\|p)\K\\{take\_fraction}(\\{right\_x}(\|p)-%
\\{right\_y}(\|p),\39\\{lambda})+\\{alpha}$;\5
$\\{right\_y}(\|p)\K\\{take\_fraction}(\\{right\_y}(\|p),\39\\{mu})+\\{beta}$;\6
$\|p\K\\{link}(\|p)$;\6
$\\{left\_x}(\|p)\K\\{take\_fraction}(\\{left\_x}(\|p)-\\{left\_y}(\|p),\39%
\\{lambda})+\\{alpha}$;\5
$\\{left\_y}(\|p)\K\\{take\_fraction}(\\{left\_y}(\|p),\39\\{mu})+\\{beta}$;\6
$\\{x\_coord}(\|p)\K\\{take\_fraction}(\\{x\_coord}(\|p)-\\{y\_coord}(\|p),\39%
\\{lambda})+\\{alpha}$;\5
$\\{y\_coord}(\|p)\K\\{take\_fraction}(\\{y\_coord}(\|p),\39\\{mu})+\\{beta}$;\6
\4\&{until}\5
$\|p=\|q$;\2\6
\&{end};\par
\fi

\M400. \P$\X400:Compute the coefficients \\{lambda}, \\{mu}, \\{alpha}, and %
\\{beta}\X\S$\6
$\\{mu\_num}\K\\{yy1}-\\{yy0}$;\5
$\\{mu\_denom}\K\\{y\_coord}(\|q)-\\{y\_coord}(\|p)$;\5
$\\{lambda\_num}\K\\{xx1}-\\{xx0}$;\5
$\\{lambda\_denom}\K\\{x\_coord}(\|q)-\\{x\_coord}(\|p)-\\{mu\_denom}$;\6
\&{if} $(\\{lambda\_num}<0)\V(\\{mu\_num}<0)\V(\\{lambda\_denom}\L0)\V(\\{mu%
\_denom}\L0)\V\30(\\{half}(\\{lambda\_num})>\\{lambda\_denom})\V(\\{half}(\\{mu%
\_num})>\\{mu\_denom})$ \1\&{then}\6
\&{begin} \37$\\{lambda}\K\\{fraction\_one}$;\5
$\\{mu}\K\\{fraction\_one}$;\5
$\\{alpha}\K0$;\5
$\\{beta}\K\\{half\_unit}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{lambda}\K\\{make\_fraction}(\\{lambda\_num},\39%
\\{lambda\_denom})$;\5
$\\{mu}\K\\{make\_fraction}(\\{mu\_num},\39\\{mu\_denom})$;\6
$\\{alpha}\K\\{xx0}-\\{take\_fraction}(\\{x\_coord}(\|p)-\\{y\_coord}(\|p),\39%
\\{lambda})$;\5
$\\{beta}\K\\{yy0}-\\{take\_fraction}(\\{y\_coord}(\|p),\39\\{mu})$;\6
\&{end};\2\par
\U section~399.\fi

\M401. Here is a procedure that computes good values $(\xbreve,\ybreve)$
corresponding
to a given $(x,y)$. The \\{transition} parameter equals \\{axis} at a
horizontal
tangent and \\{diagonal} at a $45↑\circ$ one.

There's also a fourth parameter that tells whether or not we are
considering the incoming endpoint $(x_0,y_0)$ or the outgoing one $(x_1,y_1)$;
this is necessary when $x\bmod1=y\bmod1$ to guarantee consistent mapping
across a diagonal transition. (We want essentially the same good value to
be found on each side of an octant boundary.)

The good results go into \\{cur\_x} and \\{cur\_y}. This procedure also sets
\\{cur\_m} and \\{cur\_n} to unscaled integer values $\round(x)$ and $%
\round(y)$,
respectively; and it sets \\{cur\_d} to 1 or~0, according as
$(x+{1\over2})\bmod1\G(y+{1\over2})\bmod1$ or not. The quantities
\\{cur\_m}, \\{cur\_n}, and \\{cur\_d} turn out to be significant in the
setup process for octant plotting, as well as the good values $(\xbreve,
\ybreve)$, and it is convenient to calculate all five things at the same time.

\Y\P$\\{make\_good}(\|x,\39\|y:\\{scaled};\,\35\\{transition}:\\{small%
\_number};\,\35\\{incoming}:\\{boolean})$;\6
\4\&{var} \37$\\{theta},\39\\{phi},\39\\{ave}$: \37\\{scaled};\C{fraction
parts}\6
\&{begin} \37$\|x\K\|x+\\{half\_unit}$;\5
$\\{cur\_m}\K\\{trunc\_unscaled}(\|x)$;\5
$\\{cur\_x}\K\\{cur\_m}\ast\\{unity}$;\5
$\\{theta}\K\|x-\\{cur\_x}$;\6
$\|y\K\|y+\\{half\_unit}$;\5
$\\{cur\_n}\K\\{trunc\_unscaled}(\|y)$;\5
$\\{cur\_y}\K\\{cur\_n}\ast\\{unity}$;\5
$\\{phi}\K\|y-\\{cur\_y}$;\6
\&{if} $\\{theta}\G\\{phi}$ \1\&{then}\5
$\\{cur\_d}\K1$\ \&{else} $\\{cur\_d}\K0$;\2\6
\&{if} $\\{transition}=\\{axis}$ \1\&{then}\5
$\\{cur\_x}\K\|x-\\{half\_unit}$\6
\4\&{else} \&{begin} \37$\\{ave}\K\\{half}(\\{theta}+\\{phi})$;\6
\&{if} $\\{ave}<\\{quarter\_unit}$ \1\&{then}\5
$\\{ave}\K\\{quarter\_unit}$\6
\4\&{else} \&{if} $\\{ave}\G\\{three\_quarter\_unit}$ \1\&{then}\5
$\\{ave}\K\\{three\_quarter\_unit}-1$;\2\2\6
\&{if} $\\{incoming}$ \1\&{then}\5
$\\{incr}(\\{phi})$;\C{switch branches when $\theta=\phi$}\2\6
\&{if} $\\{theta}<\\{phi}$ \1\&{then}\6
\&{begin} \37$\\{theta}\K\\{ave}-\\{three\_quarter\_unit}$;\5
$\\{phi}\K\\{ave}-\\{quarter\_unit}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{theta}\K\\{ave}-\\{quarter\_unit}$;\5
$\\{phi}\K\\{ave}-\\{three\_quarter\_unit}$;\6
\&{end};\2\6
$\\{cur\_x}\K\\{cur\_x}+\\{theta}$;\5
$\\{cur\_y}\K\\{cur\_y}+\\{phi}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M402. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{cur\_m},\39\\{cur\_n},\39\\{cur\_d}$: \37\\{integer};\C{auxiliary outputs
of \\{make\_good}}\par
\fi

\M403. We're ready now to fill the pixels enclosed by a given cycle spec~\|h;
the knot list that represents the cycle is destroyed in the process.
The edge structure that gets all the resulting data is \\{cur\_edges},
and the edges are weighted by \\{cur\_wt}.

\Y\P\4\&{procedure}\1\  \37$\\{fill\_spec}(\|h:\\{pointer})$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list traversal}\6
$\\{m0},\39\\{n0},\39\\{m1},\39\\{n1}$: \37\\{integer};\C{pixel reference
points}\6
$\\{xx0},\39\\{yy0}$: \37\\{scaled};\C{rounded and skewed coordinates}\6
\\{octant}: \37\\{small\_number};\C{the current octant code}\2\6
\&{begin} \37$\|p\K\|h$;\C{we assume that $\\{left\_type}(\|h)=\\{endpoint}$}\6
\1\&{repeat} \37$\\{octant}\K\\{left\_octant}(\|p)$;\5
\X404:Set \|q to the node at the end of the current octant\X;\6
\&{if} $\|q\I\|p$ \1\&{then}\6
\&{begin} \37\X405:Skew all the coordinates between \|p and \|q; set $(\\{m0},%
\\{n0})$ and $(\\{m1},\\{n1})$ to the starting and ending lattice points\X;\6
\X406:Make the moves for the current octant\X;\6
$\\{move\_to\_edges}(\\{m0},\39\\{n0},\39\\{m1},\39\\{n1},\39\\{octant})$;\6
\&{end};\2\6
$\|p\K\\{link}(\|q)$;\6
\4\&{until}\5
$\|p=\|h$;\2\6
$\\{toss\_knot\_list}(\|h)$;\6
\&{end};\par
\fi

\M404. \P$\X404:Set \|q to the node at the end of the current octant\X\S$\6
$\|q\K\|p$;\6
\&{while} $\\{right\_type}(\|q)\I\\{endpoint}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$\2\par
\U sections~403 and~441.\fi

\M405. \P$\X405:Skew all the coordinates between \|p and \|q; set $(\\{m0},%
\\{n0})$ and $(\\{m1},\\{n1})$ to the starting and ending lattice points\X\S$\6
$\\{make\_good}(\\{x\_coord}(\|p),\39\\{y\_coord}(\|p),\39\\{left\_transition}(%
\|p),\39\\{true})$;\5
$\\{m0}\K\\{cur\_m}$;\5
$\\{n0}\K\\{cur\_n}$;\5
$\\{d0}\K\\{cur\_d}$;\5
$\\{xx0}\K\\{cur\_x}-\\{cur\_y}$;\5
$\\{yy0}\K\\{cur\_y}+\\{half\_unit}$;\6
$\\{make\_good}(\\{x\_coord}(\|q),\39\\{y\_coord}(\|q),\39\\{right%
\_transition}(\|q),\39\\{false})$;\5
$\\{m1}\K\\{cur\_m}$;\5
$\\{n1}\K\\{cur\_n}$;\5
$\\{d1}\K\\{cur\_d}$;\5
$\\{skew}(\|p,\39\|q,\39\\{xx0},\39\\{yy0},\39\\{cur\_x}-\\{cur\_y},\39\\{cur%
\_y}+\\{half\_unit})$\par
\U section~403.\fi

\M406. \P$\X406:Make the moves for the current octant\X\S$\6
\&{if} $\\{n1}-\\{n0}\G\\{move\_size}$ \1\&{then}\5
$\\{overflow}(\.{"move\ table\ size"},\39\\{move\_size})$;\2\6
$\\{move}[0]\K\\{d0}$;\5
$\\{move\_ptr}\K0$;\5
$\|r\K\|p$;\6
\1\&{repeat} \37$\|s\K\\{link}(\|r)$;\5
$\\{make\_moves}(\\{x\_coord}(\|r),\39\\{right\_x}(\|r),\39\\{left\_x}(\|s),\39%
\\{x\_coord}(\|s),\39\30\\{y\_coord}(\|r),\39\\{right\_y}(\|r),\39\\{left\_y}(%
\|s),\39\\{y\_coord}(\|s))$;\5
$\|r\K\|s$;\6
\4\&{until}\5
$\|r=\|q$;\2\6
$\\{move}[\\{move\_ptr}]\K\\{move}[\\{move\_ptr}]-\\{d1}$\par
\U section~403.\fi

\N407.  \[xx] Polygonal pens.
The next few parts of the program deal with the additional complications
associated with ``envelopes,'' leading up to an algorithm that fills a
contour with respect to a pen whose boundary is a convex polygon. The
mathematics underlying this algorithm is based on simple aspects of the
theory of tracings developed by Leo Guibas, Lyle Ramshaw, and Jorge
Stolfi [``A kinetic framework for computational geometry,''
{\sl Proc.\ IEEE Symp.\ Foundations of Computer Science\/ \bf24} (1983),
100--111].

If the vertices of the polygon are $w_0$, $w_1$, \dots, $w_{n-1}$, $w_n=w_0$,
in counterclockwise order, the convexity condition requires that ``left
turns'' are made at each vertex when a person proceeds from $w_0$ to
$w_1$ to $\cdots$ to~$w_n$. The envelope is obtained if we offset a given
curve $z(t)$ by $w_k$ when that curve is traveling in a direction
$z'(t)$ lying between the directions $w\k-w_k$ and $w_k-w_{k-1}$.
At times~$t$ when the curve direction $z'(t)$ increases past
$w\k-w_k$, we temporarily stop plotting the offset curve and we insert
a straight line from $z(t)+w_k$ to $z(t)+w\k$; notice that this straight
line is tangent to the offset curve. Similarly, when the curve direction
decreases past $w_k-w_{k-1}$, we stop plotting and insert a straight
line from $z(t)+w_k$ to $z(t)+w_{k-1}$; the latter line is actually a
``retrograde'' step, which won't be part of the final envelope under
\MF's assumptions. The result of this construction is a continuous path
that onsists of alternating curves and straight line segments. The
segments are usually so short, in practice, that they blend with the
curves; after all, it's possible to represent any digitized path as
a sequence of digitized straight lines.

The nicest feature of this approach to envelopes is that it blends
perfectly with the octant subdivision process we have already developed.
The envelope travels in the same direction as the curve itself, as we
plot it, and we need merely be careful what offset is being added.
Retrograde motion presents a problem, but we will see that there is
a decent way to handle it.

\fi

\M408. We shall represent pens by maintaining eight lists of offsets,
one for each octant direction. The offsets at the boundary points
where a curve turns into a new octant will appear in the lists for
both octants. This means that we can restrict consideration to
segments of the original polygon whose directions aim in the first
octant, as we have done in the simpler case when envelopes were not
required.

An example should help to clarify this situation: Consider the
quadrilateral whose vertices are $w_0=(0,-1)$, $w_1=(3,-1)$,
$w_2=(6,1)$, and $w_3=(1,2)$. A curve that travels in the first octant
will be offset by $w_1$ or $w_2$, unless its slope drops to zero
enroute to the eighth octant; in the latter case we should switch to $w_0$ as
we cross the octant boundary. Our list for the first octant will
contain the three offsets $w_0$, $w_1$,~$w_2$. By convention we will
duplicate a boundary offset if the angle between octants doesn't
explicitly appear; in this case there is no explicit line of slope~1
at the end of the list, so the full list is
$$w_0\;w_1\;w_2\;w_2\;=\;(0,-1)\;(3,-1)\;(6,1)\;(6,1).$$
With skewed coordinates $(u-v,v)$ instead of $(u,v)$ we obtain the list
$$w_0\;w_1\;w_2\;w_2\;\mapsto\;(1,-1)\;(4,-1)\;(5,1)\;(5,1),$$
which is what actually appears in the data structure. In the second
octant there's only one offset; we list it three times (with coordinates
interchanged, so as to make the second octant look like the first),
and skew those coordinates, obtaining
$$\halign{$\hfil#\;\mapsto\;{}$&$#\hfil$&\quad in the #\hfil\cr
w_2\;w_2\;w_2&(-5,6)\;(-5,6)\;(-5,6)\cr
\noalign{\vskip\belowdisplayskip
\vbox{\noindent\strut as the list of transformed and skewed offsets to use
when curves that travel in the second octant. Similarly, we will have\strut}
\vskip\abovedisplayskip}
w_2\;w_2\;w_2&(7,-6)\;(7,-6)\;(7,-6)&third;\cr
w_2\;w_2\;w_3\;w_3&(-7,1)\;(-7,1)\;(-3,2)\;(-3,2)&fourth;\cr
w_3\;w_3\;w_3&(3,-2)\;(3,-2)\;(3,-2)&fifth;\cr
w_3\;w_3\;w_0\;w_0&(-3,1)\;(-3,1)\;(1,0)\;(1,0)&sixth;\cr
w_0\;w_0\;w_0&(1,0)\;(1,0)\;(1,0)&seventh;\cr
w_0\;w_0\;w_0&(-1,1)\;(-1,1)\;(-1,1)&eighth.\cr}$$
Notice that $w_1$ is considered here to be internal to the first octant;
it's not part of the eighth. We could equally well have taken $w_0$ out
of the first octant list and put it into the eighth; then the first octant
list would have been
$$w_1\;w_1\;w_2\;w_2\;\mapsto\;(4,-1)\;(4,-1)\;(5,1)\;(5,1)$$
and the eighth octant list would have been
$$w_0\;w_0\;w_1\;\mapsto\;(-1,1)\;(-1,1)\;(2,1).$$

Actually, there's one more complication: The order of offsets is reversed
in even-numbered octants, because the transformation of coordinates has
reversed counterclockwise and clockwise orientations in those octants.
The offsets in the fourth octant, for example, are really $w_3$, $w_3$,
$w_2$,~$w_2$, not $w_2$, $w_2$, $w_3$,~$w_3$.

\fi

\M409. In general, the list of offsets for an octant will have the form
$$w_0\;\;w_1\;\;\ldots\;\;w_n\;\;w_{n+1}$$
(if we renumber the subscripts in each list), where $w_0$ and $w_{n+1}$
are offsets common to the neighboring lists. We'll often have $w_0=w_1$
and/or $w_n=w_{n+1}$, but the other $w$'s will be distinct. Curves
that travel between slope~0 and direction $w_2-w_1$ will use offset~$w_1$;
curves that travel between directions $w_k-w_{k-1}$ and $w\k-w_k$ will
use offset~$w_k$, for $1<k<n$; curves between direction $w_n-w_{n-1}$
and slope~1 (actually slope~$\infty$ after skewing) will use offset~$w~n$.
In even-numbered octants, the directions are actually $w_k-w\k$ instead
of $w\k-w_k$, because the offsets have been listed in reverse order.

Each offset $w_k$ is represented by skewed coordinates $(u_k-v_k,v_k)$,
where $(u_k,v_k)$ is the representation of $w_k$ after it has been rotated
into a first-octant disguise. (This rotation should use negation
rather than the ones' complement, when variables change sign.)

\fi

\M410. The top-level data structure of a pen polygon is a 9-word node
containing
a reference count followed by
pointers to the eight pen lists. If \|p~points to such a node, and if the
offset list for say the fourth octant has entries $w_0$, $w_1$, \dots,
$w_n$~$w_{n+1}$, then $\\{info}(\|p+\\{fourth\_octant})$ will equal~$n$, and
$\\{link}(\|p+\\{fourth\_octant})$ will point to the offset node
containing~$w_0$.
Memory location $\|p+\\{fourth\_octant}$ is said to be the {\sl header\/} of
the pen-offset list for the fourth octant. Since this is an even-numbered
octant, $w_0$ is the offset that goes with the fifth octant, and
$w_{n+1}$ goes with the third.

The elements of the offset list themselves are doubly linked 3-word nodes,
containing coordinates in their \\{x\_coord} and \\{y\_coord} fields.
The two link fields are called \\{link} and \\{knil}; if \|w~points to
the node for~$w_k$, then $\\{link}(\|w)$ and $\\{knil}(\|w)$ point respectively
to the nodes for $w\k$ and~$w_{k-1}$. If \|h is the list header,
$\\{link}(\|h)$ points to the node for~$w_0$ and $\\{knil}(\\{link}(\|h))$ to
the
node for~$w_{n+1}$.

The tenth word of a pen header node contains the maximum absolute value of
an $x$ or $y$ coordinate among all of the pen offsets. (FIXTHIS: compute it!)

\Y\P\D \37$\\{pen\_node\_size}=10$\par
\P\D \37$\\{max\_offset}(\#)\S\\{mem}[\#+9].\\{sc}$\par
\fi

\M411. The \\{print\_pen} subroutine illustrates these conventions by
reconstructing the vertices of a polygon from \MF's complicated
internal offset representation.

\Y\P\4\&{procedure}\1\  \37$\\{print\_pen}(\|p:\\{pointer};\,\35\|s:\\{str%
\_number})$; \6
\4\&{var} \37\\{nothing\_printed}: \37\\{boolean};\C{has there been any action
yet?}\6
$\|k,\39\\{octant}$: \37$1\to8$;\C{octant number and code}\6
\|h: \37\\{pointer};\C{offset list head}\6
$\|m,\39\|n$: \37\\{integer};\C{offset indices}\6
$\|w,\39\\{ww}$: \37\\{pointer};\C{pointers that traverse the offset list}\6
\|m: \\{integer} \6
\&{begin} \37$\\{print\_diagnostic}(\.{"Pen\ polygon"},\39\|s)$;\5
$\\{nothing\_printed}\K\\{true}$;\6
\&{for} $\|k\K1\mathrel{\&{to}}8$ \1\&{do}\6
\&{begin} \37$\\{octant}\K\\{octant\_code}[\|k]$;\5
$\|h\K\|p+\\{octant}$;\5
$\|n\K\\{info}(\|h)$;\5
$\|w\K\\{link}(\|h)$;\6
\&{if} $\R\\{odd}(\|k)$ \1\&{then}\5
$\|w\K\\{knil}(\|w)$;\C{in even octants, start at $w_{n+1}$}\2\6
\&{for} $\|m\K1\mathrel{\&{to}}\|n+1$ \1\&{do}\6
\&{begin} \37\&{if} $\\{odd}(\|k)$ \1\&{then}\5
$\\{ww}\K\\{link}(\|w)$\ \&{else} $\\{ww}\K\\{knil}(\|w)$;\2\6
\&{if} $(\\{x\_coord}(\\{ww})\I\\{x\_coord}(\|w))\V(\\{y\_coord}(\\{ww})\I\\{y%
\_coord}(\\{ww}))$ \1\&{then}\5
\X412:Print the unskewed and unrotated coordinates of node \\{ww}\X;\2\6
$\|w\K\\{ww}$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{nothing\_printed}$ \1\&{then}\6
\&{begin} \37$\|w\K\\{link}(\|p)$;\5
$\\{print\_two}(\\{x\_coord}(\|w)+\\{y\_coord}(\|w),\39\\{y\_coord}(\|w))$;\6
\&{end};\2\6
$\\{print\_nl}(\.{"\ ..\ cycle"})$;\5
$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\par
\fi

\M412. Here we can't use \\{unrotate} because we don't want ones' complements.

\Y\P$\4\X412:Print the unskewed and unrotated coordinates of node \\{ww}\X\S$\6
\&{begin} \37\&{if} $\\{nothing\_printed}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
$\\{nothing\_printed}\K\\{false}$;\6
\&{end}\6
\4\&{else} $\\{print\_nl}(\.{"\ ..\ "})$;\2\6
\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37$\\{print\_two}(\\{x\_coord}(\\{ww})+\\{y\_coord}(%
\\{ww}),\39\\{y\_coord}(\\{ww}))$;\6
\4\\{second\_octant}: \37$\\{print\_two}(\\{y\_coord}(\\{ww}),\39\\{x\_coord}(%
\\{ww})+\\{y\_coord}(\\{ww}))$;\6
\4\\{third\_octant}: \37$\\{print\_two}(-\\{y\_coord}(\\{ww}),\39\\{x\_coord}(%
\\{ww}),\39\\{y\_coord}(\\{ww}))$;\6
\4\\{fourth\_octant}: \37$\\{print\_two}(-\\{x\_coord}(\\{ww})-\\{y\_coord}(%
\\{ww}),\39\\{y\_coord}(\\{ww}))$;\6
\4\\{fifth\_octant}: \37$\\{print\_two}(-\\{x\_coord}(\\{ww})-\\{y\_coord}(%
\\{ww})-\\{y\_coord}(\\{ww}))$;\6
\4\\{sixth\_octant}: \37$\\{print\_two}(-\\{y\_coord}(\\{ww}),\39-\\{x\_coord}(%
\\{ww})-\\{y\_coord}(\\{ww}))$;\6
\4\\{seventh\_octant}: \37$\\{print\_two}(\\{y\_coord}(\\{ww}),\39-\\{x%
\_coord}(\\{ww})-\\{y\_coord}(\\{ww}))$;\6
\4\\{eighth\_octant}: \37$\\{print\_two}(\\{x\_coord}(\\{ww})+\\{y\_coord}(%
\\{ww}),\39-\\{y\_coord}(\\{ww}))$;\2\6
\&{end};\C{there are no other cases}\6
\&{end}\par
\U section~411.\fi

\M413. A null pen polygon, which has just one vertex $(0,0)$, is
predeclared for error recovery.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{ref\_count}(\\{null\_pen})\K1$;\5
$\\{link}(\\{null\_pen})\K\\{null}$;\5
$\\{info}(\\{null\_pen}+1)\K1$;\5
$\\{link}(\\{null\_pen}+1)\K\\{null\_coords}$;\6
\&{for} $\|k\K\\{null\_pen}+2\mathrel{\&{to}}\\{null\_pen}+8$ \1\&{do}\5
$\\{mem}[\|k]\K\\{mem}[\\{null\_pen}]$;\2\6
$\\{link}(\\{null\_coords})\K\\{null\_coords}$;\5
$\\{knil}(\\{null\_coords})\K\\{null\_coords}$;\5
$\\{x\_coord}(\\{null\_coords})\K0$;\5
$\\{y\_coord}(\\{null\_coords})\K0$;\par
\fi

\M414. Here's a trivial subroutine that inserts a copy of an offset
on the \\{link} side of its clone in the doubly linked list.

\Y\P\4\&{procedure}\1\  \37$\\{dup\_offset}(\|w:\\{pointer})$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|r\K\\{get\_node}(\\{coord\_node\_size})$;\5
$\\{x\_coord}(\|r)\K\\{x\_coord}(\|w)$;\5
$\\{y\_coord}(\|r)\K\\{y\_coord}(\|w)$;\5
$\\{link}(\|r)\K\\{link}(\|w)$;\5
$\\{knil}(\\{link}(\|w))\K\|r$;\5
$\\{knil}(\|r)\K\|w$;\5
$\\{link}(\|w)\K\|r$;\6
\&{end};\par
\fi

\M415. The following algorithm is somewhat more interesting: It converts a
knot list for a cyclic path into a pen polygon, ignoring everything
but the \\{x\_coord}, \\{y\_coord}, and \\{link} fields. If the given path
vertices do not define a convex polygon, an error message is issued
and the null pen is returned.

\Y\P\4\&{procedure}\1\  \37$\\{make\_pen}(\|h:\\{pointer})$: \37\\{pointer};\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{not\_found},\39\\{found}$;\6
\4\&{var} \37$\|o,\39\\{oo},\39\|k$: \37\\{small\_number};\C{octant
numbers---old, new, and current}\6
\|p: \37\\{pointer};\C{top-level node for the new pen}\6
$\|q,\39\|r,\39\|s,\39\|w,\39\\{ww},\39\|h,\39\\{hh}$: \37\\{pointer};\C{for
list manipulation}\6
\|n: \37\\{integer};\C{offset counter}\6
$\\{dx},\39\\{dy}$: \37\\{scaled};\C{polygon direction}\6
\\{octant}: \37$1\to8$;\C{octant code at current node}\2\6
\&{begin} \37\X418:Stamp all nodes with an octant code, and set \\{hh} to the
node that begins the first octant; \&{goto} \\{not\_found} if there's a problem%
\X;\6
$\|p\K\\{get\_node}(\\{pen\_node\_size})$;\5
$\|q\K\\{hh}$;\6
\&{for} $\|k\K1\mathrel{\&{to}}8$ \1\&{do}\5
\X420:Construct the offset list for the \|kth octant\X;\2\6
\&{goto} \37\\{found};\6
\4\\{not\_found}: \37$\|p\K\\{null\_pen}$;\5
\X416:Complain about a bad pen path\X;\6
\4\\{found}: \37\&{if} $\\{internal}[\\{tracing\_pens}]>0$ \1\&{then}\5
$\\{print\_pen}(\|p,\39\.{"(newly\ created)"})$;\2\6
$\\{make\_pen}\K\|p$;\6
\&{end};\par
\fi

\M416. \P$\X416:Complain about a bad pen path\X\S$\6
$\\{print\_err}(\.{"Pen\ cycle\ must\ be\ convex"})$;\5
$\\{help3}(\.{"The\ cycle\ you\ specified\ either\ has\ consecutive\ equal\
points"})$\6
$(\.{"or\ turns\ right\ or\ turns\ through\ more\ than\ 360\ degrees."})$\6
$(\.{"So\ I\'ve\ replaced\ it\ by\ the\ short\ cycle\ \`0,0..cycle\'."})$;\6
\\{error}\par
\U section~415.\fi

\M417. There should be exactly one node whose octant number is less than its
predecessor in the cycle; that is node~\\{hh}.

The loop here will terminate in all cases, but the proof is somewhat tricky:
If there are at least two distinct $y$~coordinates in the cycle, we will have
$\|o>4$ and $\|o\L4$ at different points of the cycle. Otherwise there are
at least two distinct $x$~coordinates, and we will have $\|o>2$ somewhere,
$\|o\L2$ somewhere.

\fi

\M418. \P$\X418:Stamp all nodes with an octant code, and set \\{hh} to the node
that begins the first octant; \&{goto} \\{not\_found} if there's a problem\X\S$%
\6
$\|q\K\|h$;\5
$\|r\K\\{link}(\|q)$;\6
\&{if} $\|q=\|r$ \1\&{then}\6
\&{begin} \37$\\{hh}\K\|h$;\5
$\\{right\_type}(\|h)\K0$;\C{this trick is explained below}\6
\&{end}\6
\4\&{else} \&{begin} \37$\|o\K0$;\5
$\\{hh}\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|s\K\\{link}(\|r)$;\5
$\\{dx}\K\\{x\_coord}(\|r)-\\{x\_coord}(\|q)$;\5
$\\{dy}\K\\{y\_coord}(\|r)-\\{y\_coord}(\|q)$;\6
\&{if} $\\{dx}=0$ \1\&{then}\6
\&{if} $\\{dy}=0$ \1\&{then}\5
\&{goto} \37\\{not\_found};\C{double point}\2\2\6
\&{if} $\R\\{ab\_geq\_cd}(\\{dx},\39\\{y\_coord}(\|s)-\\{y\_coord}(\|r),\39%
\\{dy},\39\\{x\_coord}(\|s)-\\{x\_coord}(\|r))$ \1\&{then}\5
\&{goto} \37\\{not\_found};\C{right turn}\2\6
\X419:Determine the \\{octant} code for direction $(\\{dx},\\{dy})$\X;\6
$\\{right\_type}(\|q)\K\\{octant}$;\5
$\\{oo}\K\\{octant\_number}[\\{octant}]$;\6
\&{if} $\|o>\\{oo}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{hh}\I\\{null}$ \1\&{then}\5
\&{goto} \37\\{not\_found};\C{$>360↑\circ$}\2\6
$\\{hh}\K\|q$;\6
\&{end};\2\6
$\|o\K\\{oo}$;\6
\&{if} $(\|q=\|h)\W(\\{hh}\I\\{null})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|q\K\|r$;\5
$\|r\K\|s$;\6
\&{end};\2\6
\4\\{done}: \37\&{end}\2\par
\U section~415.\fi

\M419. \P$\X419:Determine the \\{octant} code for direction $(\\{dx},\\{dy})$\X%
\S$\6
$\\{octant}\K\\{first\_octant}$;\6
\&{if} $\\{dx}<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\\{dx})$;\5
$\\{octant}\K\\{first\_octant}+\\{negate\_x}$;\6
\&{end};\2\6
\&{if} $\\{dy}<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\\{dy})$;\5
$\\{octant}\K\\{octant}+\\{negate\_y}$;\6
\&{end};\2\6
\&{if} $\\{dx}<\\{dy}$ \1\&{then}\5
$\\{octant}\K\\{octant}+\\{swap\_x\_y}$\2\par
\U section~418.\fi

\M420. Now \|q points to the node that the present octant shares with the
previous
octant, and $\\{right\_type}(\|q)$ is the octant code during which \|q~should
advance.
We have set $\\{right\_type}(\|q)=0$ in the special case that \|q should never
advance
(because the pen is degenerate).

\Y\P$\4\X420:Construct the offset list for the \|kth octant\X\S$\6
$\\{octant}\K\\{octant\_code}(\|k)$;\5
$\|n\K0$;\5
$\|h\K\|p+\\{octant}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|r\K\\{get\_node}(\\{coord\_node\_size})$;\5
\X421:Transform the coordinates of node \|q to \\{octant}, skewed, and put them
into node \|r\X;\6
\&{if} $\|n=0$ \1\&{then}\5
$\\{link}(\|h)\K\|r$\6
\4\&{else} \X422:Link node \|r to the previous node\X;\2\6
$\|w\K\|r$;\6
\&{if} $\\{right\_type}(\|q)\I\\{octant}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\|q\K\\{link}(\|q)$;\5
$\\{incr}(\|n)$;\6
\&{end};\2\6
\4\\{done1}: \37\X423:Finish linking the offset nodes, and duplicate the
borderline offset nodes if necessary\X;\6
$\\{info}(\|h)\K\|n$\par
\U section~415.\fi

\M421. \P\D \37$\\{skew\_two\_tail}(\#)\S\#$;\5
$\\{y\_coord}(\|r)\K\#$;\ \&{end} \par
\P\D $\\{skew\_two}(\#)\S$ \6
\&{begin} \37$\\{x\_coord}(\|r)\K\#-\\{skew\_two\_tail}$\par
\Y\P$\4\X421:Transform the coordinates of node \|q to \\{octant}, skewed, and
put them into node \|r\X\S$\6
\&{case} $\\{octant}$ \1\&{of}\6
\4\\{first\_octant}: \37$\\{skew\_two}(\\{x\_coord}(\|q))(\\{y\_coord}(\|q))$;\6
\4\\{second\_octant}: \37$\\{skew\_two}(\\{y\_coord}(\|q))(\\{x\_coord}(\|q))$;%
\6
\4\\{third\_octant}: \37$\\{skew\_two}(\\{y\_coord}(\|q))(-\\{x\_coord}(\|q))$;%
\6
\4\\{fourth\_octant}: \37$\\{skew\_two}(-\\{x\_coord}(\|q))(\\{y\_coord}(%
\|q))$;\6
\4\\{fifth\_octant}: \37$\\{skew\_two}(-\\{x\_coord}(\|q))(-\\{y\_coord}(%
\|q))$;\6
\4\\{sixth\_octant}: \37$\\{skew\_two}(-\\{y\_coord}(\|q))(-\\{x\_coord}(%
\|q))$;\6
\4\\{seventh\_octant}: \37$\\{skew\_two}(-\\{y\_coord}(\|q))(\\{x\_coord}(%
\|q))$;\6
\4\\{eighth\_octant}: \37$\\{skew\_two}(\\{x\_coord}(\|q))(-\\{y\_coord}(%
\|q))$;\2\6
\&{end}\C{there are no other cases}\par
\U section~420.\fi

\M422. Now \|w points to the node that was inserted most recently, and
\|k is the current octant number.

\Y\P$\4\X422:Link node \|r to the previous node\X\S$\6
\&{if} $\\{odd}(\|k)$ \1\&{then}\6
\&{begin} \37$\\{link}(\|w)\K\|r$;\5
$\\{knil}(\|r)\K\|w$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{knil}(\|w)\K\|r$;\5
$\\{link}(\|r)\K\|w$;\6
\&{end}\2\par
\U section~420.\fi

\M423. We have inserted $\|n+1$ nodes; it remains to duplicate the nodes at the
ends, if slopes 0 and~$\infty$ aren't already represented. At the end of
this section the total number of offset nodes should be $\|n+2$
(since we call them $w_0$, $w_1$, \dots,~$w_{n+1}$).

\Y\P$\4\X423:Finish linking the offset nodes, and duplicate the borderline
offset nodes if necessary\X\S$\6
$\|r\K\\{link}(\|h)$;\6
\&{if} $\\{odd}(\|k)$ \1\&{then}\6
\&{begin} \37$\\{link}(\|w)\K\|r$;\5
$\\{knil}(\|r)\K\|w$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{knil}(\|w)\K\|r$;\5
$\\{link}(\|r)\K\|w$;\5
$\\{link}(\|h)\K\|w$;\5
$\|r\K\|w$;\6
\&{end};\2\6
\&{if} $\\{y\_coord}(\|r)\I\\{y\_coord}(\\{link}(\|r))$ \1\&{then}\6
\&{begin} \37$\\{dup\_offset}(\|r)$;\5
$\\{incr}(\|n)$;\6
\&{end};\2\6
$\|r\K\\{knil}(\|r)$;\6
\&{if} $\\{x\_coord}(\|r)\I\\{x\_coord}(\\{knil}(\|r))$ \1\&{then}\5
$\\{dup\_offset}(\|r)$\6
\4\&{else} $\\{decr}(\|n)$\2\par
\U section~420.\fi

\M424. That which can be created can be destroyed.

\Y\P\4\&{procedure}\1\  \37$\\{toss\_pen}(\|p:\\{pointer})$;\6
\4\&{var} \37\|k: \37$0\to7$;\C{relative header locations}\6
$\|w,\39\\{ww}$: \37\\{pointer};\C{pointers to offset nodes}\6
\&{begin} \37\&{if} $\|p\I\\{null\_pen}$ \1\&{then}\6
\&{begin} \37\&{for} $\|k\K0\mathrel{\&{to}}7$ \1\&{do}\6
\&{begin} \37$\|w\K\\{link}(\|p+\|k)$;\6
\1\&{repeat} \37$\\{ww}\K\\{link}(\|w)$;\5
$\\{free\_node}(\|w,\39\\{coord\_node\_size})$;\5
$\|w\K\\{ww}$;\6
\4\&{until}\5
$\|w=\\{link}(\|p+\|k)$;\2\6
$\\{free\_node}(\|p,\39\\{pen\_node\_size})$;\6
\&{end};\2\6
\&{end};\2\par
\fi

\N425.  \[xx] Filling an envelope.
We are about to reach the culmination of \MF's digital plotting routines:
Almost all of the previous algorithms will be brought of bear on \MF's
most difficult task, which is to fill the envelope of a given cyclic path
with respect to a given pen polygon.

But we still must complete some of the preparatory work before taking such
a big plunge.

\fi

\M426. Given a pointer \|c to a nonempty list of cubics,
and a pointer~\|h to the header information of a pen polygon segment,
the \\{offset\_prep} routine changes the list into cubics that are
associated with particular pen offsets. Namely, the cubic between \|p
and~\|q should be associated with the \|kth offset when $\\{right\_type}(\|p)=%
\|k$.

List \|c is actually part of a cycle spec, so it terminates at the
first node whose \\{right\_type} is \\{endpoint}. The cubics all have
monotone-nondecreasing $x'(t)$ and $y'(t)$.

\Y\P\X428:Declare subroutines needed by \\{offset\_prep}\X\6
\4\&{procedure}\1\  \37$\\{offset\_prep}(\|c,\39\|h:\\{pointer})$;\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|n: \37\\{halfword};\C{the number of pen offsets}\6
$\|p,\39\|q,\39\|r,\39\\{ww}$: \37\\{pointer};\C{for list manipulation}\6
\|k: \37\\{halfword};\C{the current offset index}\6
\|w: \37\\{pointer};\C{a pointer to offset $w_k$}\6
\X430:Other local variables for \\{offset\_prep}\X\2\6
\&{begin} \37$\|p\K\|c$;\5
$\|n\K\\{info}(\|h)$;\5
$\|h\K\\{link}(\|h)$;\C{now \|h points to $w_0$}\6
\&{while} $\\{right\_type}(\|p)\I\\{endpoint}$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
\X429:Split the cubic between \|p and \|q, if necessary, into cubics associated
with single offsets, after which \|q should point to the end of the final such
cubic\X;\6
\X427:Advance \|p to node \|q, removing any ``dead'' cubics that might have
been introduced by the splitting process\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M427. \P$\X427:Advance \|p to node \|q, removing any ``dead'' cubics that
might have been introduced by the splitting process\X\S$\6
\1\&{repeat} \37$\|r\K\\{link}(\|p)$;\6
\&{if} $\\{x\_coord}(\|p)=\\{right\_x}(\|p)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{right\_y}(\|p)$ \1\&{then}\6
\&{if} $\\{x\_coord}(\|p)=\\{left\_x}(\|r)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{left\_y}(\|r)$ \1\&{then}\6
\&{if} $\\{x\_coord}(\|p)=\\{x\_coord}(\|r)$ \1\&{then}\6
\&{if} $\\{y\_coord}(\|p)=\\{y\_coord}(\|r)$ \1\&{then}\6
\&{begin} \37$\\{remove\_cubic}(\|p)$;\6
\&{if} $\|r=\|q$ \1\&{then}\5
$\|q\K\|p$;\2\6
$\|r\K\|p$;\6
\&{end};\2\2\2\2\2\2\6
$\|p\K\|r$;\6
\4\&{until}\5
$\|p=\|q$\2\par
\U section~426.\fi

\M428. The splitting process uses a subroutine like \\{split\_cubic}, but
it is simpler than the subroutine needed by \\{make\_spec} because
the coordinate values are all consistent with each other.

\Y\P$\4\X428:Declare subroutines needed by \\{offset\_prep}\X\S$\6
\4\&{procedure}\1\  \37$\\{split\_for\_offset}(\|p:\\{pointer};\,\35\|t:%
\\{fraction})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the successor of \|p}\6
\|s: \37\\{quarterword};\C{temporary storage for $\\{right\_type}(\|q)$}\2\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\|s\K\\{right\_type}(\|q)$;\5
$\\{right\_type}(\|q)\K\\{first\_octant}$;\5
$\\{right\_type}(\|p)\K\\{first\_octant}$;\5
$\\{split\_cubic}(\|p,\39\|t)$;\5
$\\{right\_type}(\|q)\K\|s$;\6
\&{end};\par
\A section~432.
\U section~426.\fi

\M429. If the pen polygon has \|n offsets, and if $w_k=(u_k,v_k)$ is the $k$th
of these, the $k$th pen slope is defined by the formula
$$s_k={v\k-v_k\over u\k-u_k},\qquad\hbox{for $0<k<n$}.$$
In odd-numbered octants, the numerator and denominator of this fraction
will be positive; in even-numbered octants they will both be negative.
Furthermore we always have $0=s_0<s_1<\cdots<s_n=\infty$. The goal of
\\{offset\_prep} is to find an offset index~\|k to associate with
each cubic, such that the slope $s(t)$ of the cubic satisfies
$$s_{k-1}≤s(t)≤s_k\qquad\hbox{for $0≤t≤1$.}\eqno(*)$$
We may have to split a cubic into as many as $2n-1$ pieces before each
piece corresponds to a unique offset.

\Y\P$\4\X429:Split the cubic between \|p and \|q, if necessary, into cubics
associated with single offsets, after which \|q should point to the end of the
final such cubic\X\S$\6
\&{if} $\|n=1$ \1\&{then}\5
$\\{right\_type}(\|p)\K1$\C{this case is easy}\6
\4\&{else} \&{begin} \37\X431:Prepare for derivative computations\X;\6
\&{if} $\\{dx}=0$ \1\&{then}\5
\X440:Handle the special case of infinite slope\X\6
\4\&{else} \&{begin} \37\X436:Find the initial slope, $\\{dy}/\\{dx}$\X;\6
\X437:Find the index \|k such that $s_{k-1}\L\\{dy}/\\{dx}<s_k$\X;\6
\X438:Complete the offset splitting process\X;\6
\&{end};\2\6
\&{end}\2\par
\U section~426.\fi

\M430. The slope of a cubic $B(z_0,z_1,z_2,z_3;t)=x(t)+iy(t)$ can be calculated
from the quadratic polynomials ${1\over3}x'(t)=B(x_1-x_0,x_2-x_1,x_3-x_2;t)$
and ${1\over3}y'(t)=B(y_1-y_0,y_2-y_1,y_3-y_2;t)$.
Since we may be calculating slopes from several cubics
split from the current one, it is desirable to do these calculations
without losing too much precision. ``Scaled up'' values of the
derivatives, which will be less tainted by accumulated errors than
derivatives found from the cubics themselves, are maintained in
local variables \\{x0}, \\{x1}, and \\{x2}, representing $X_0=2↑m(x_1-x_0)$,
$X_1=2↑m(x_2-x_1)$, and $X_2=2↑m(x_3-x_2)$; similarly \\{y0}, \\{y1}, and~%
\\{y2}
represent $Y_0=2↑m(y_1-y_0)$, $Y_1=2↑m(y_2-y_1)$, and $Y_2=2↑m(y_3-y_2)$.
To test whether the slope of the cubic is $≥s$ or $≤s$, we will test
the sign of the quadratic ${1\over3}2↑m\bigl(y'(t)-sx'(t)\bigr)$ if $s≤1$,
or ${1\over3}2↑m\bigl(y'(t)/s-x'(t)\bigr)$ if $s>1$.

\Y\P$\4\X430:Other local variables for \\{offset\_prep}\X\S$\6
\4$\\{x0},\39\\{x1},\39\\{x2},\39\\{y0},\39\\{y1},\39\\{y2}$: \37\\{integer};%
\C{representatives of derivatives}\6
\4$\\{t0},\39\\{t1},\39\\{t2}$: \37\\{integer};\C{coefficients of polynomial
for slope testing}\6
\4$\\{du},\39\\{dv},\39\\{dx},\39\\{dy}$: \37\\{integer};\C{for slopes of the
pen and the curve}\6
\4\\{max\_coef}: \37\\{integer};\C{used while scaling}\6
\4$\\{x0a},\39\\{x1a},\39\\{x2a},\39\\{y0a},\39\\{y1a},\39\\{y2a}$: \37%
\\{inteer};\C{intermediate values}\par
\U section~426.\fi

\M431. \P$\X431:Prepare for derivative computations\X\S$\6
$\\{x0}\K\\{right\_x}(\|p)-\\{x\_coeff}(\|p)$;\C{should be $\G0$}\6
$\\{x2}\K\\{x\_coeff}(\|q)-\\{left\_x}(\|q)$;\C{likewise}\6
$\\{x1}\K\\{left\_x}(\|q)-\\{right\_x}(\|p)$;\C{but this might be negative}\6
$\\{y0}\K\\{right\_y}(\|p)-\\{y\_coeff}(\|p)$;\5
$\\{y2}\K\\{y\_coeff}(\|q)-\\{left\_y}(\|q)$;\5
$\\{y1}\K\\{left\_y}(\|q)-\\{right\_y}(\|p)$;\5
$\\{max\_coef}\K\\{abs}(\\{x0})$;\C{we take \\{abs} just to make sure}\6
\&{if} $\\{abs}(\\{x1})>\\{max\_coef}$ \1\&{then}\5
$\\{max\_coef}\K\\{abs}(\\{x1})$;\2\6
\&{if} $\\{abs}(\\{x2})>\\{max\_coef}$ \1\&{then}\5
$\\{max\_coef}\K\\{abs}(\\{x2})$;\2\6
\&{if} $\\{abs}(\\{y0})>\\{max\_coef}$ \1\&{then}\5
$\\{max\_coef}\K\\{abs}(\\{y0})$;\2\6
\&{if} $\\{abs}(\\{y1})>\\{max\_coef}$ \1\&{then}\5
$\\{max\_coef}\K\\{abs}(\\{y1})$;\2\6
\&{if} $\\{abs}(\\{y2})>\\{max\_coef}$ \1\&{then}\5
$\\{max\_coef}\K\\{abs}(\\{y2})$;\2\6
\&{while} $\\{max\_coef}<\\{fraction\_one}$ \1\&{do}\6
\&{begin} \37$\\{max\_coef}\K\\{max\_coef}+\\{max\_coef}$;\5
$\\{x0}\K\\{x0}+\\{x0}$;\5
$\\{x1}\K\\{x1}+\\{x1}$;\5
$\\{x2}\K\\{x2}+\\{x2}$;\5
$\\{y0}\K\\{y0}+\\{y0}$;\5
$\\{y1}\K\\{y1}+\\{y1}$;\5
$\\{y2}\K\\{y2}+\\{y2}$;\6
\&{end};\2\par
\U section~429.\fi

\M432. Let us first solve a special case of the problem: Suppose we
know an index~$k$ such that either (i)~$s(t)\G s_{k-1}$ for all~$t$
and $s(0)<s_k$, or (ii)~$s(t)\L s_k$ for all~$t$ and $s(0)>s_{k-1}$.
Then, in a sense, we're halfway done, since one of the two inequalities
in $(*)$ is satisfied, and the other couldn't be satisfied for
any other value of~\|k.

The \\{fin\_offset\_prep} subroutine solves the stated subproblems.
It has a boolean parameter called \\{rising} that is \\{true} in
case~(i), \\{false} in case~(ii). When $\\{rising}=\\{false}$, parameters
\\{x0} through \\{y2} represent the negative of the derivative of
the cubic following \|p; otherwise they represent the actual derivative.
The \|w parameter whould point to offset~$w_k$.

\Y\P$\4\X428:Declare subroutines needed by \\{offset\_prep}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{fin\_offset\_prep}(\|p:\\{pointer};\,\35\|k:%
\\{halfword};\,\35\|w:\\{pointer};\,\35\\{x0},\39\\{x1},\39\\{x2},\39\\{y0},\39%
\\{y1},\39\\{y2}:\\{integer};\,\35\\{rising}:\\{boolean})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|q,\39\\{ww}$: \37\\{pointer};\C{for list manipulation}\6
$\\{du},\39\\{dv}$: \37\\{scaled};\C{for slope calculation}\6
$\\{t0},\39\\{t1},\39\\{t2}$: \37\\{integer};\C{test coefficients}\6
\|t: \37\\{fraction};\C{place where the derivative passes a critical slope}\6
\|v: \37\\{integer};\C{intermediate value for updating $\\{x0}\to\\{y2}$}\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\5
$\\{right\_type}(\|p)\K\|k$;\6
\&{if} $\\{rising}$ \1\&{then}\6
\&{if} $\|k=\|n$ \1\&{then}\5
\&{return}\6
\4\&{else} $\\{ww}\K\\{link}(\|w)$\C{a pointer to $w\k$}\2\6
\4\&{else} \&{if} $\|k=0$ \1\&{then}\5
\&{return}\6
\4\&{else} $\\{ww}\K\\{knil}(\|w)$;\C{a pointer to $w_{k-1}$}\2\2\6
\X433:Compute test coefficients $(\\{t0},\\{t1},\\{t2})$ for $s(t)$ versus
$s_{k\pm1}$\X;\6
$\|t\K\\{crossing\_point}(\\{t0},\39\\{t1},\39\\{t2})$;\6
\&{if} $\|t\G\\{fraction\_one}$ \1\&{then}\5
\&{return};\2\6
\X434:Split the cubic at $t$, and split off another cubic if the derivative
crosses back\X;\6
\&{if} $\\{rising}$ \1\&{then}\5
$\\{incr}(\|k)$\ \&{else} $\\{decr}(\|k)$;\2\6
$\|w\K\\{ww}$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M433. \P$\X433:Compute test coefficients $(\\{t0},\\{t1},\\{t2})$ for $s(t)$
versus $s_{k\pm1}$\X\S$\6
$\\{du}\K\\{x\_coord}(\\{ww})-\\{x\_coord}(\|w)$;\5
$\\{dv}\K\\{y\_coord}(\\{ww})-\\{y\_coord}(\|w)$;\6
\&{if} $\\{abs}(\\{du})\G\\{abs}(\\{dv})$ \1\&{then}\C{$s_{k\pm1}≤1$}\6
\&{begin} \37$\\{t0}\K\\{take\_fraction}(\\{x0},\39\\{make\_fraction}(\\{dv},%
\39\\{du}))-\\{y0}$;\5
$\\{t1}\K\\{take\_fraction}(\\{x1},\39\\{make\_fraction}(\\{dv},\39\\{du}))-%
\\{y1}$;\5
$\\{t2}\K\\{take\_fraction}(\\{x2},\39\\{make\_fraction}(\\{dv},\39\\{du}))-%
\\{y2}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{t0}\K\\{x0}-\\{take\_fraction}(\\{y0},\39\\{make%
\_fraction}(\\{du},\39\\{dv}))$;\5
$\\{t1}\K\\{x1}-\\{take\_fraction}(\\{y1},\39\\{make\_fraction}(\\{du},\39%
\\{dv}))$;\5
$\\{t2}\K\\{x2}-\\{take\_fraction}(\\{y2},\39\\{make\_fraction}(\\{du},\39%
\\{dv}))$;\6
\&{end}\2\par
\U sections~432 and~438.\fi

\M434. The curve has crossed $s_{k\pm1}$; its initial segment satisfies $(*)$,
and it might cross again and return towards $s_k$, yielding another
solution of $(*)$.

\Y\P$\4\X434:Split the cubic at $t$, and split off another cubic if the
derivative crosses back\X\S$\6
\&{begin} \37$\\{split\_for\_offset}(\|p,\39\|t)$;\5
$\\{right\_type}(\|p)\K\|k$;\5
$\|p\K\\{link}(\|p)$;\6
$\|v\K\\{t\_of\_the\_way}(\\{x0})(\\{x1})$;\5
$\\{x1}\K\\{t\_of\_the\_way}(\\{x1})(\\{x2})$;\5
$\\{x0}\K\\{t\_of\_the\_way}(\|v)(\\{x1})$;\6
$\|v\K\\{t\_of\_the\_way}(\\{y0})(\\{y1})$;\5
$\\{y1}\K\\{t\_of\_the\_way}(\\{y1})(\\{y2})$;\5
$\\{y0}\K\\{t\_of\_the\_way}(\|v)(\\{y1})$;\6
$\\{t1}\K\\{t\_of\_the\_way}(\\{t1})(\\{t2})$;\6
\&{if} $\\{t1}>0$ \1\&{then}\5
$\\{t1}\K0$;\C{without rounding error, \\{t1} would be $\L0$}\2\6
$\|t\K\\{crossing\_point}(0,\39-\\{t1},\39-\\{t2})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\6
\&{begin} \37$\\{split\_for\_offset}(\|p,\39\|t)$;\5
$\\{right\_type}(\|q)\K\|k$;\6
$\|v\K\\{t\_of\_the\_way}(\\{x1})(\\{x2})$;\5
$\\{x1}\K\\{t\_of\_the\_way}(\\{x0})(\\{x1})$;\5
$\\{x2}\K\\{t\_of\_the\_way}(\\{x1})(\|v)$;\6
$\|v\K\\{t\_of\_the\_way}(\\{y1})(\\{y2})$;\5
$\\{y1}\K\\{t\_of\_the\_way}(\\{y0})(\\{y1})$;\5
$\\{y2}\K\\{t\_of\_the\_way}(\\{y1})(\|v)$;\6
\&{end};\2\6
\&{end}\par
\U section~432.\fi

\M435. Now we must consider the general problem of \\{offset\_prep}, when
nothing is known about a given cubic. We start by finding its
slope $s(0)$ in the vicinity of $\|t=0$.

If $z'(t)=0$, the given cubic is numerically unstable, since the
slope direction is probably being influenced primarily by rounding
errors. A user who specifies such cuspy curves should expect to generate
rather wild results. The present code tries its best to believe the
existing data, as if no rounding errors were present.

\fi

\M436. \P$\X436:Find the initial slope, $\\{dy}/\\{dx}$\X\S$\6
$\\{dx}\K\\{x0}$;\5
$\\{dy}\K\\{y0}$;\6
\&{if} $\\{dx}=0$ \1\&{then}\6
\&{if} $\\{dy}=0$ \1\&{then}\6
\&{begin} \37$\\{dx}\K\\{x1}$;\5
$\\{dy}\K\\{y1}$;\6
\&{if} $\\{dx}=0$ \1\&{then}\6
\&{if} $\\{dy}=0$ \1\&{then}\6
\&{begin} \37$\\{dx}\K\\{x2}$;\5
$\\{dy}\K\\{y2}$;\6
\&{end};\2\2\6
\&{end}\2\2\par
\U section~429.\fi

\M437. The next step is to bracket the initial slope between consecutive
slopes of the pen polygon. The invariant relation in the following
loop is that $\\{dy}/\\{dx}\G\hbox{$s_{k-1}$}$.

\Y\P$\4\X437:Find the index \|k such that $s_{k-1}\L\\{dy}/\\{dx}<s_k$\X\S$\6
$\|k\K1$;\5
$\|w\K\\{link}(\|h)$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{ww}\K\\{link}(\|w)$;\6
\&{if} $\|k<\|n$ \1\&{then}\6
\&{if} $\\{ab\_geq\_cd}(\\{dy},\39\\{abs}(\\{x\_coord}(\\{ww})-\\{x\_coord}(%
\|w)),\39\30\\{dx},\39\\{abs}(\\{y\_coord}(\\{ww})-\\{y\_coord}(\|w)))$ \1%
\&{then}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\|w\K\\{ww}$;\6
\&{end}\6
\4\&{else} \&{goto} \37\\{done};\2\2\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~429.\fi

\M438. Finally we want to reduce the general problem to situations that
\\{fin\_offset\_prep} can handle. If $\|k=1$, we already are in the desired
situation. Otherwise we can split the cubic into at most three parts
with respect to $s_{k-1}$, and apply \\{fin\_offset\_prep} to each part.

\Y\P$\4\X438:Complete the offset splitting process\X\S$\6
\&{if} $\|k=1$ \1\&{then}\5
$\|t\K\\{fraction\_one}+1$\6
\4\&{else} \&{begin} \37$\\{ww}\K\\{knil}(\|w)$;\5
\X433:Compute test coefficients $(\\{t0},\\{t1},\\{t2})$ for $s(t)$ versus
$s_{k\pm1}$\X;\6
$\|t\K\\{crossing\_point}(\\{t0},\39\\{t1},\39\\{t2})$;\6
\&{end};\2\6
\&{if} $\|t\G\\{fraction\_one}$ \1\&{then}\5
$\\{fin\_offset\_prep}(\|p,\39\|k,\39\|w,\39\\{x0},\39\\{x1},\39\\{x2},\39%
\\{y0},\39\\{y1},\39\\{y2},\39\\{true})$\6
\4\&{else} \&{begin} \37$\\{split\_for\_offset}(\|p,\39\|t)$;\5
$\|r\K\\{link}(\|p)$;\6
$\\{x1a}\K\\{t\_of\_the\_way}(\\{x0})(\\{x1})$;\5
$\\{x1}\K\\{t\_of\_the\_way}(\\{x1})(\\{x2})$;\5
$\\{x2a}\K\\{t\_of\_the\_way}(\\{x10})(\\{x1})$;\6
$\\{y1a}\K\\{t\_of\_the\_way}(\\{y0})(\\{y1})$;\5
$\\{y1}\K\\{t\_of\_the\_way}(\\{y1})(\\{y2})$;\5
$\\{y2a}\K\\{t\_of\_the\_way}(\\{y10})(\\{y1})$;\6
$\\{fin\_offset\_prep}(\|p,\39\|k,\39\|w,\39\\{x0},\39\\{x1a},\39\\{x2a},\39%
\\{y0},\39\\{y1a},\39\\{y2a},\39\\{true})$;\5
$\\{x0}\K\\{x2a}$;\5
$\\{y0}\K\\{y2a}$;\5
$\\{t1}\K\\{t\_of\_the\_way}(\\{t1})(\\{t2})$;\6
\&{if} $\\{t1}>0$ \1\&{then}\5
$\\{t1}\K0$;\2\6
$\|t\K\\{crossing\_point}(0,\39-\\{t1},\39-\\{t2})$;\6
\&{if} $\|t<\\{fraction\_one}$ \1\&{then}\5
\X439:Split off another \\{rising} cubic for \\{fin\_offset\_prep}\X;\2\6
$\\{fin\_offset\_prep}(\|r,\39\|k-1,\39\\{ww},\39-\\{x0},\39-\\{x1},\39-\\{x2},%
\39-\\{y0},\39-\\{y1},\39-\\{y2},\39\\{false})$;\6
\&{end}\2\par
\U section~429.\fi

\M439. \P$\X439:Split off another \\{rising} cubic for \\{fin\_offset\_prep}\X%
\S$\6
\&{begin} \37$\\{split\_for\_offset}(\|r,\39\|t)$;\6
$\\{x1a}\K\\{t\_of\_the\_way}(\\{x1})(\\{x2})$;\5
$\\{x1}\K\\{t\_of\_the\_way}(\\{x0})(\\{x1})$;\5
$\\{x0a}\K\\{t\_of\_the\_way}(\\{x1})(\\{x1a})$;\6
$\\{y1a}\K\\{t\_of\_the\_way}(\\{y1})(\\{y2})$;\5
$\\{y1}\K\\{t\_of\_the\_way}(\\{y0})(\\{y1})$;\5
$\\{y0a}\K\\{t\_of\_the\_way}(\\{y1})(\\{y1a})$;\6
$\\{fin\_offset\_prep}(\\{link}(\|r),\39\|k,\39\|w,\39\\{x0a},\39\\{x1a},\39%
\\{x2},\39\\{y0a},\39\\{y1a},\39\\{y2},\39\\{true})$;\5
$\\{x2}\K\\{x0a}$;\5
$\\{y2}\K\\{y0a}$;\6
\&{end}\par
\U section~438.\fi

\M440. \P$\X440:Handle the special case of infinite slope\X\S$\6
$\\{fin\_offset\_prep}(\|p,\39\|n,\39\\{knil}(\\{knil}(\|h)),\39-\\{x0},\39-%
\\{x1},\39-\\{x2},\39-\\{y0},\39-\\{y1},\39-\\{y2},\39\\{false})$\par
\U section~429.\fi

\M441. OK, it's time now for the biggie. The \\{fill\_envelope} routine
generalizes
\\{fill\_spec} to polygonal envelopes. Its outer structure is essentially the
same as before, except that octants with no cubics do contribute to
the envelope.

\Y\P\X447:Declare the procedure called \\{skew\_line\_edges}\X\6
\4\&{procedure}\1\  \37$\\{fill\_envelope}(\\{spec\_head},\39\\{pen\_head}:%
\\{pointer})$;\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{done2}$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list traversal}\6
\|h: \37\\{pointer};\C{head of pen offset list for current octant}\6
$\\{m0},\39\\{n0},\39\\{m1},\39\\{n1}$: \37\\{integer};\C{lattice point
coordinates}\6
$\\{xx},\39\\{yy},\39\\{xp},\39\\{yp},\39\\{delx},\39\\{dely},\39\\{temp}$: \37%
\\{scaled};\C{registers for coordinate calculations}\6
\\{octant}: \37\\{small\_number};\C{the current octant code}\6
\X444:Other local variables for \\{fill\_envelope}\X\2\6
\&{begin} \37$\|p\K\\{spec\_head}$;\C{we assume that $\\{left\_type}(\\{spec%
\_head})=\\{endpoint}$}\6
\1\&{repeat} \37$\\{octant}\K\\{left\_octant}(\|p)$;\5
$\|h\K\\{pen\_head}+\\{octant}-1$;\5
\X404:Set \|q to the node at the end of the current octant\X;\6
\X442:Skew all the coordinates between \|p and \|q; set $(\\{m0},\\{n0})$ and
$(\\{m1},\\{n1})$ to the starting and ending envelope lattice points\X;\6
$\\{offset\_prep}(\|p,\39\|h)$;\5
\X445:Make the envelope moves for the current octant and insert them in the
pixel data\X;\6
$\|p\K\\{link}(\|q)$;\6
\4\&{until}\5
$\|p=\\{spec\_head}$;\2\6
$\\{toss\_knot\_list}(\\{spec\_head})$;\6
\&{end};\par
\fi

\M442. At an \\{axis} transition, the current \|z is offset by $w_0$, whose
coordinates relative to the first octant are $(u_0+v_0,v_0)$ since they
have already been skewed. Similarly, the current point \|z is offset at
a \\{diagonal} transition by $(u_{n+1}+v_{n+1},v_{n+1})$. The offset points
are rounded to good equivalents as in \\{fill\_spec}.

\Y\P$\4\X442:Skew all the coordinates between \|p and \|q; set $(\\{m0},%
\\{n0})$ and $(\\{m1},\\{n1})$ to the starting and ending envelope lattice
points\X\S$\6
$\\{x0}\K\\{x\_coord}(\|p)$;\5
$\\{y0}\K\\{y\_coord}(\|p)$;\5
$\\{x1}\K\\{x\_coord}(\|q)$;\5
$\\{y1}\K\\{y\_coord}(\|q)$;\6
$\|w\K\\{link}(\|h)$;\ \&{if} $\\{left\_transition}(\|p)=\\{diagonal}$ \1%
\&{then}\5
$\|w\K\\{knil}(\|w)$;\2\6
$\\{make\_good}(\\{x0}+\\{x\_coord}(\|w)+\\{y\_coord}(\|w),\39\\{y0}+\\{y%
\_coord}(\|w),\39\\{left\_transition}(\|p),\39\\{true})$;\6
$\\{m0}\K\\{cur\_m}$;\5
$\\{n0}\K\\{cur\_n}$;\5
$\\{d0}\K\\{cur\_d}$;\6
$\\{xx}\K(\\{cur\_x}-\\{cur\_y})-\\{x\_coord}(\|w)$;\5
$\\{yy}\K\\{cur\_y}+\\{half\_unit}-\\{y\_coord}(\|w)$;\6
$\|w\K\\{link}(\|h)$;\ \&{if} $\\{right\_transition}(\|q)=\\{diagonal}$ \1%
\&{then}\5
$\|w\K\\{knil}(\|w)$;\2\6
$\\{make\_good}(\\{x1}+\\{x\_coord}(\|w)+\\{y\_coord}(\|w),\39\\{y1}+\\{y%
\_coord}(\|w),\39\\{right\_transition}(\|q),\39\\{false})$;\6
$\\{m1}\K\\{cur\_m}$;\5
$\\{n1}\K\\{cur\_n}$;\5
$\\{d1}\K\\{cur\_d}$;\5
$\\{skew}(\|p,\39\|q,\39\\{xx},\39\\{yy},\39\\{cur\_x}-\\{cur\_y}-\\{x\_coord}(%
\|w),\39\\{cur\_y}+\\{half\_unit}-\\{y\_coord}(\|w))$\par
\U section~441.\fi

\M443. In even-numbered octans we have reflected the coordinates an odd number
of times, hence clockwise and counterclockwise are reversed; this means that
the envelope is being formed in a ``dual'' manner. For the time being, let's
concentrate on odd-numbered octants, since they're easier to understand.
Once we have coded the program for odd-numbered octants, the changes needed
to dualize it will not be so mysterious.

It is convenient to assume that we enter an odd-numbered octant with
an \\{axis} transition (where the skewed slope is zero) and leave at a
\\{diagonal} one (where the skewed slope is infinite). Then all of the
offset points $z(t)+w(t)$ will lie in a rectangle whose lower left and
upper right corners are the initial and final offset points. If this
assumption doesn't hold we can implicitly change the curve so that it does.
For example, if the entering transition is diagonal, we can draw a
straight line from $z_0+w_{n+1}$ to $z_0+w_0$ and continue as if the
curve were moving rightward. The effect of this on the envelope is simply
to ``doubly color'' the region enveloped by a section of the pen that
goes from $w_0$ to $w_1$ to $\cdots$ to $w_{n+1}$ to~$w_0$. The additional
straight line at the beginning (and a similar one at the end, where it
may be necessary to go from $z_1+w_{n+1}$ to $z_1+w_0$) can be drawn by
the \\{line\_edges} routine; we are thereby saved from the embarrassment that
these lines travel backwards from the current octant direction.

Once we have established the assumption that the curve goes from
$z_0+w_0$ to $z_1+w_{n+1}$, any further retrograde moves that might
occur within the octant can be essentially ignored; we merely need to
keep track of the rightmost edge in each row, in order to compute
the envelope.

Envelope moves consist of offset cubics intermixed with straight line
segments. We record them in a separate \\{env\_move} array, which is
something like \\{move} but it keeps track of the rightmost position of the
envelope in each row.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{env\_move}: \37\&{array} $[0\to\\{move\_size}]$ \1\&{of}\5
\\{integer};\2\par
\fi

\M444. The envelope calculations require more local variables than we needed
in the simpler case of \\{fill\_spec}. At critical points in the computation,
\|w will point to offset $w_k$;
$m$ will be $\lfloor$\\{x\_coord}(\|r)$+$\\{x\_coord}(\|w)$\rfloor$ and \\{move%
\_ptr} will
be $\lfloor$\\{y\_coord}(\|r)$+$\\{y\_coord}(\|w)$\rfloor-\\{nn0}$.

\Y\P$\4\X444:Other local variables for \\{fill\_envelope}\X\S$\6
\4$\\{xx0},\39\\{yy0},\39\\{xx1},\39\\{yy1}$: \37\\{scaled};\C{skewed
coordinates at start and finish}\6
\4$\\{mm0},\39\\{nn0},\39\\{mm1},\39\\{nn1}$: \37\\{integer};\C{starting and
finishing lattice points}\6
\4$\|m,\39\|n$: \37\\{integer};\C{current lattice position}\6
\4\|k: \37\\{integer};\C{current offset number}\6
\4$\|w,\39\\{ww}$: \37\\{pointer};\C{pointers to the current offset and its
neighbor}\par
\U section~441.\fi

\M445. \P$\X445:Make the envelope moves for the current octant and insert them
in the pixel data\X\S$\6
\&{if} $\\{odd}(\\{octant\_number}[\\{octant}])$ \1\&{then}\6
\&{begin} \37\X446:Initialize for ordinary envelope moves\X;\6
$\|r\K\|p$;\5
$\\{right\_type}(\|q)\K\\{info}(\|h)+1$;\6
\~ \1\&{loop}\ \&{begin} \37\&{while} $\\{right\_type}(\|r)\I\|k$ \1\&{do}\5
\X450:Insert a line segment to approach the correct offset\X;\2\6
\&{if} $\|r=\|q$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{move}[\\{move\_ptr}]\K0$;\5
$\|n\K\\{move\_ptr}$;\5
$\|s\K\\{link}(\|r)$;\5
$\\{make\_moves}(\\{x\_coord}(\|r)+\\{x\_coord}(\|w),\39\\{right\_x}(\|r)+\\{x%
\_coord}(\|w),\39\30\\{left\_x}(\|s)+\\{x\_coord}(\|w),\39\\{x\_coord}(\|s)+%
\\{x\_coord}(\|w),\39\30\\{y\_coord}(\|r)+\\{y\_coord}(\|w),\39\\{right\_y}(%
\|r)+\\{y\_coord}(\|w),\39\30\\{left\_y}(\|s)+\\{y\_coord}(\|w),\39\\{y%
\_coord}(\|s)+\\{y\_coord}(\|w))$;\5
\X449:Transfer moves from the \\{move} array to \\{env\_move}\X;\6
$\|r\K\|s$;\6
\&{end};\2\6
\X452:Insert the new envelope moves in the pixel data\X;\6
\&{end}\6
\4\&{else} \X453:Make dual envelope moves for the current octant and insert
them in the pixel data\X;\2\6
\4\\{done}: \37\par
\U section~441.\fi

\M446. \P$\X446:Initialize for ordinary envelope moves\X\S$\6
$\|k\K0$;\5
$\|w\K\\{link}(\|h)$;\5
$\\{ww}\K\\{knil}(\|w)$;\6
$\\{xx0}\K\\{x\_coord}(\|p)+\\{x\_coord}(\|w)$;\5
$\\{yy0}\K\\{y\_coord}(\|p)+\\{y\_coord}(\|w)$;\6
\&{if} $\\{left\_transition}(\|p)=\\{diagonal}$ \1\&{then}\5
\X448:Change the entering transition by inserting a straight line\X;\2\6
$\\{xx1}\K\\{x\_coord}(\|q)+\\{x\_coord}(\\{ww})$;\5
$\\{yy1}\K\\{y\_coord}(\|q)+\\{y\_coord}(\\{ww})$;\5
$\\{nn0}\K\\{trunc\_unscaled}(\\{yy0})$;\5
$\\{nn1}\K\\{trunc\_unscaled}(\\{yy1})$;\6
\&{if} $\\{nn1}-\\{nn0}\G\\{move\_size}$ \1\&{then}\5
$\\{overflow}(\.{"move\ table\ size"},\39\\{move\_size})$;\2\6
$\\{mm0}\K\\{trunc\_unscaled}(\\{xx0})$;\5
$\\{mm1}\K\\{trunc\_unscaled}(\\{xx1})$;\6
\&{for} $\\{move\_ptr}\K0\mathrel{\&{to}}\\{nn1}-\\{nn0}$ \1\&{do}\5
$\\{env\_move}[\\{move\_ptr}]\K\\{mm0}$;\2\6
$\\{env\_move}[\\{nn1}-\\{nn0}]\K\\{mm1}$;\5
$\\{move\_ptr}\K0$;\5
$\|m\K\\{mm0}$\par
\U section~445.\fi

\M447. It's convenient to have a slight variation of the \\{line\_edges}
procedure
when we must draw the retrograde lines for nonstandard entry and exit
conditions.

\Y\P$\4\X447:Declare the procedure called \\{skew\_line\_edges}\X\S$\6
\4\&{procedure}\1\  \37$\\{skew\_line\_edges}(\\{x0},\39\\{y0},\39\\{x1},\39%
\\{y1}:\\{scaled};\,\35\\{octant}:\\{small\_number})$;\2\6
\&{begin} \37$\\{unrotate}(\\{x0}+\\{y0},\39\\{y0}-\\{half\_unit},\39%
\\{octant})$;\C{unskew and unrotate the coordinates}\6
$\\{x0}\K\\{cur\_x}$;\5
$\\{y0}\K\\{cur\_y}$;\5
$\\{unrotate}(\\{x1}+\\{y1},\39\\{y1}-\\{half\_unit},\39\\{octant})$;\5
$\\{line\_edges}(\\{x0},\39\\{y0},\39\\{cur\_x},\39\\{cur\_y})$;\C{then draw a
straight line}\6
\&{end};\par
\U section~441.\fi

\M448. \P$\X448:Change the entering transition by inserting a straight line\X%
\S$\6
\&{begin} \37$\\{skew\_line\_edges}(\\{x\_coord}(\|p)+\\{x\_coord}(\\{ww}),\39%
\\{y\_coord}(\|p)+\\{y\_coord}(\\{ww}),\39\\{xx0},\39\\{yy0},\39\\{octant})$;\5
$\\{xx}\K\\{xx0}+\\{yy0}$;\5
$\\{yy}\K\\{yy0}-\\{half\_unit}$;\5
$\\{m0}\K\\{round\_unscaled}(\\{xx})$;\5
$\\{n0}\K\\{round\_unscaled}(\\{yy})$;\6
\&{if} $\\{xx}-\\{m0}\ast\\{unity}\G\\{yy}-\\{n0}\ast\\{unity}$ \1\&{then}\5
$\\{d0}\K1$\ \&{else} $\\{d0}\K0$;\2\6
\&{end}\par
\U sections~446 and~454.\fi

\M449. At this point \|n holds the value of \\{move\_ptr} that was current
when \\{make\_moves} began to record its moves.

\Y\P$\4\X449:Transfer moves from the \\{move} array to \\{env\_move}\X\S$\6
\1\&{repeat} \37$\|m\K\|m+\\{move}[\|n]-1$;\6
\&{if} $\|m>\\{env\_move}[\|n]$ \1\&{then}\5
$\\{env\_move}[\|n]\K\|m$;\2\6
$\\{incr}(\|n)$;\6
\4\&{until}\5
$\|n>\\{move\_ptr}$\2\par
\U section~445.\fi

\M450. Retrograde lines (when \|k decreases) do not need to be recorded in
\\{env\_move} because their edges are not the furthest right in any row.

\Y\P$\4\X450:Insert a line segment to approach the correct offset\X\S$\6
\&{begin} \37$\\{xx}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yy}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{if} $\\{right\_type}(\|r)>\|k$ \1\&{then}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\|w\K\\{link}(\|w)$;\5
$\\{xp}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yp}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{if} $(\\{xp}\I\\{xx})\V(\\{yp}\I\\{yy})$ \1\&{then}\5
\X451:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},\\{yp})$ in %
\\{env\_move}\X;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{decr}(\|k)$;\5
$\|w\K\\{knil}(\|w)$;\5
$\\{xp}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yp}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{end};\2\6
$\|m\K\\{trunc\_unscaled}(\\{xp})$;\5
$\\{move\_ptr}\K\\{trunc\_unscaled}(\\{yp})-\\{nn0}$;\6
\&{end}\par
\U section~445.\fi

\M451. \P$\X451:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},%
\\{yp})$ in \\{env\_move}\X\S$\6
\&{begin} \37$\\{temp}\K\\{trunc\_scaled}(\\{yy})$;\5
$\\{yy}\K\\{yy}-\\{temp}$;\5
$\\{yp}\K\\{yp}-\\{temp}$;\6
\&{if} $\\{yp}\G\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{delx}\K\\{xp}-\\{xx}$;\5
$\\{dely}\K\\{yp}-\\{yy}$;\5
$\\{yy}\K\\{unity}-1-\\{yy}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|m\K\\{round\_unscaled}(\\{xx}+\\{take%
\_fraction}(\\{delx},\39\\{make\_fraction}(\\{yy},\39\\{dely})))$;\6
\&{if} $\|m>\\{env\_move}[\\{move\_ptr}]$ \1\&{then}\5
$\\{env\_move}[\\{move\_ptr}]\K\|m$;\2\6
$\\{yp}\K\\{yp}-\\{unity}$;\6
\&{if} $\\{yp}<\\{unity}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\\{yy}\K\\{yy}+\\{unity}$;\5
$\\{incr}(\\{move\_ptr})$;\6
\&{end};\2\6
\4\\{done1}: \37\&{end};\2\6
\&{end}\par
\U section~450.\fi

\M452. \P$\X452:Insert the new envelope moves in the pixel data\X\S$\6
\&{if} $\\{right\_transition}(\|q)=\\{axis}$ \1\&{then}\6
\&{begin} \37$\\{xx}\K\\{xx1}+\\{yy1}$;\5
$\\{yy}\K\\{yy1}-\\{half\_unit}$;\5
$\\{m1}\K\\{round\_unscaled}(\\{xx})$;\5
$\\{n1}\K\\{round\_unscaled}(\\{yy})$;\6
\&{if} $\\{xx}-\\{m1}\ast\\{unity}\G\\{yy}-\\{n1}\ast\\{unity}$ \1\&{then}\5
$\\{d1}\K1$\ \&{else} $\\{d1}\K0$;\2\6
\&{end};\2\6
$\\{move}[0]\K\\{d0}+\\{env\_move}[0]-\\{mm0}$;\6
\&{for} $\|n\K1\mathrel{\&{to}}\\{move\_ptr}$ \1\&{do}\5
$\\{move}[\|n]\K\\{env\_move}[\|n]-\\{env\_move}[\|n-1]+1$;\2\6
$\\{move}[\\{move\_ptr}]\K\\{move}[\\{move\_ptr}]-\\{d1}$;\5
\\{smooth\_moves};\5
$\\{move\_to\_edges}(\\{m0},\39\\{n0},\39\\{m1},\39\\{n1},\39\\{octant})$;\6
\&{if} $\\{right\_transition}(\|q)=\\{axis}$ \1\&{then}\6
\&{begin} \37$\\{ww}\K\\{link}(\|h)$;\5
$\\{skew\_line\_edges}(\\{xx1},\39\\{yy1},\39\\{x\_coord}(\|q)+\\{x\_coord}(%
\\{ww}),\39\\{y\_coord}(\|q)+\\{y\_coord}(\\{ww}),\39\\{octant})$;\6
\&{end}\2\par
\U section~445.\fi

\M453. OK, now we've done it all in the odd-octant case; the only thing
remaining
is to repeat the same ideas, upside down and/or backwards.

\Y\P$\4\X453:Make dual envelope moves for the current octant and insert them in
the pixel data\X\S$\6
\&{begin} \37\X454:Initialize for dual envelope moves\X;\6
$\|r\K\|p$;\5
$\\{right\_type}(\|q)\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\&{while} $\\{right\_type}(\|r)\I\|k$ \1\&{do}\5
\X456:Insert a line segment dually to approach the correct offset\X;\2\6
\&{if} $\|r=\|q$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{move}[\\{move\_ptr}]\K0$;\5
$\|n\K\\{move\_ptr}$;\5
$\|s\K\\{link}(\|r)$;\5
$\\{make\_moves}(\\{x\_coord}(\|r)+\\{x\_coord}(\|w),\39\\{right\_x}(\|r)+\\{x%
\_coord}(\|w),\39\30\\{left\_x}(\|s)+\\{x\_coord}(\|w),\39\\{x\_coord}(\|s)+%
\\{x\_coord}(\|w),\39\30\\{y\_coord}(\|r)+\\{y\_coord}(\|w),\39\\{right\_y}(%
\|r)+\\{y\_coord}(\|w),\39\30\\{left\_y}(\|s)+\\{y\_coord}(\|w),\39\\{y%
\_coord}(\|s)+\\{y\_coord}(\|w))$;\5
\X455:Transfer moves dually from the \\{move} array to \\{env\_move}\X;\6
$\|r\K\|s$;\6
\&{end};\2\6
\X458:Insert the new envelope moves dually in the pixel data\X;\6
\&{end}\par
\U section~445.\fi

\M454. In the dual case the normal situation is to arrive with a \\{diagonal}
transition and to leave at the \\{axis}. The leftmost edge in each row
is relevant instead of the rightmost one.

\Y\P$\4\X454:Initialize for dual envelope moves\X\S$\6
$\|k\K\\{info}(\|h)+1$;\5
$\\{ww}\K\\{link}(\|h)$;\5
$\|w\K\\{knil}(\\{ww})$;\6
$\\{xx0}\K\\{x\_coord}(\|p)+\\{x\_coord}(\|w)$;\5
$\\{yy0}\K\\{y\_coord}(\|p)+\\{y\_coord}(\|w)$;\6
\&{if} $\\{left\_transition}(\|p)=\\{axis}$ \1\&{then}\5
\X448:Change the entering transition by inserting a straight line\X;\2\6
$\\{xx1}\K\\{x\_coord}(\|q)+\\{x\_coord}(\\{ww})$;\5
$\\{yy1}\K\\{y\_coord}(\|q)+\\{y\_coord}(\\{ww})$;\5
$\\{nn0}\K\\{trunc\_unscaled}(\\{yy0})$;\5
$\\{nn1}\K\\{trunc\_unscaled}(\\{yy1})$;\6
\&{if} $\\{nn1}-\\{nn0}\G\\{move\_size}$ \1\&{then}\5
$\\{overflow}(\.{"move\ table\ size"},\39\\{move\_size})$;\2\6
$\\{mm0}\K\\{trunc\_unscaled}(\\{xx0})$;\5
$\\{mm1}\K\\{trunc\_unscaled}(\\{xx1})$;\6
\&{for} $\\{move\_ptr}\K1\mathrel{\&{to}}\\{nn1}-\\{nn0}$ \1\&{do}\5
$\\{env\_move}[\\{move\_ptr}]\K\\{mm1}$;\2\6
$\\{env\_move}[0]\K\\{mm0}$;\5
$\\{move\_ptr}\K0$;\5
$\|m\K\\{mm0}$\par
\U section~453.\fi

\M455. \P$\X455:Transfer moves dually from the \\{move} array to \\{env\_move}%
\X\S$\6
\1\&{repeat} \37$\|m\K\|m+\\{move}[\|n]-1$;\6
\&{if} $\|m<\\{env\_move}[\|n]$ \1\&{then}\5
$\\{env\_move}[\|n]\K\|m$;\2\6
$\\{incr}(\|n)$;\6
\4\&{until}\5
$\|n>\\{move\_ptr}$\2\par
\U section~453.\fi

\M456. Dual retrograde lines occur when \|k increases; the edges of such lines
are not the furthest left in any row.

\Y\P$\4\X456:Insert a line segment dually to approach the correct offset\X\S$\6
\&{begin} \37$\\{xx}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yy}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{if} $\\{right\_type}(\|r)<\|k$ \1\&{then}\6
\&{begin} \37$\\{decr}(\|k)$;\5
$\|w\K\\{knil}(\|w)$;\5
$\\{xp}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yp}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{if} $(\\{xp}\I\\{xx})\V(\\{yp}\I\\{yy})$ \1\&{then}\5
\X457:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},\\{yp})$ dually
in \\{env\_move}\X;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{incr}(\|k)$;\5
$\|w\K\\{link}(\|w)$;\5
$\\{xp}\K\\{x\_coord}(\|r)+\\{x\_coord}(\|w)$;\5
$\\{yp}\K\\{y\_coord}(\|r)+\\{y\_coord}(\|w)$;\6
\&{end};\2\6
$\|m\K\\{trunc\_unscaled}(\\{xp})$;\5
$\\{move\_ptr}\K\\{trunc\_unscaled}(\\{yp})-\\{nn0}$;\6
\&{end}\par
\U section~453.\fi

\M457. \P$\X457:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},%
\\{yp})$ dually in \\{env\_move}\X\S$\6
\&{begin} \37$\\{temp}\K\\{trunc\_scaled}(\\{yy})$;\5
$\\{yy}\K\\{yy}-\\{temp}$;\5
$\\{yp}\K\\{yp}-\\{temp}$;\6
\&{if} $\\{yp}\G\\{unity}$ \1\&{then}\6
\&{begin} \37$\\{delx}\K\\{xp}-\\{xx}$;\5
$\\{dely}\K\\{yp}-\\{yy}$;\5
$\\{yy}\K\\{unity}-1-\\{yy}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|m\K\\{round\_unscaled}(\\{xx}+\\{take%
\_fraction}(\\{delx},\39\\{make\_fraction}(\\{yy},\39\\{dely})))$;\6
\&{if} $\|m<\\{env\_move}[\\{move\_ptr}]$ \1\&{then}\5
$\\{env\_move}[\\{move\_ptr}]\K\|m$;\2\6
$\\{yp}\K\\{yp}-\\{unity}$;\6
\&{if} $\\{yp}<\\{unity}$ \1\&{then}\5
\&{goto} \37\\{done2};\2\6
$\\{yy}\K\\{yy}+\\{unity}$;\5
$\\{incr}(\\{move\_ptr})$;\6
\&{end};\2\6
\4\\{done2}: \37\&{end};\2\6
\&{end}\par
\U section~456.\fi

\M458. \P$\X458:Insert the new envelope moves dually in the pixel data\X\S$\6
\&{if} $\\{right\_transition}(\|q)=\\{diagonal}$ \1\&{then}\6
\&{begin} \37$\\{xx}\K\\{xx1}+\\{yy1}$;\5
$\\{yy}\K\\{yy1}-\\{half\_unit}$;\5
$\\{m1}\K\\{round\_unscaled}(\\{xx})$;\5
$\\{n1}\K\\{round\_unscaled}(\\{yy})$;\6
\&{if} $\\{xx}-\\{m1}\ast\\{unity}\G\\{yy}-\\{n1}\ast\\{unity}$ \1\&{then}\5
$\\{d1}\K1$\ \&{else} $\\{d1}\K0$;\2\6
\&{end};\2\6
$\\{move}[0]\K\\{d0}+\\{env\_move}[0]-\\{mm0}$;\6
\&{for} $\|n\K1\mathrel{\&{to}}\\{move\_ptr}$ \1\&{do}\5
$\\{move}[\|n]\K\\{env\_move}[\|n]-\\{env\_move}[\|n-1]+1$;\2\6
$\\{move}[\\{move\_ptr}]\K\\{move}[\\{move\_ptr}]-\\{d1}$;\5
\\{smooth\_moves};\5
$\\{move\_to\_edges}(\\{m0},\39\\{n0},\39\\{m1},\39\\{n1},\39\\{octant})$;\6
\&{if} $\\{right\_transition}(\|q)=\\{diagonal}$ \1\&{then}\6
\&{begin} \37$\\{ww}\K\\{link}(\|h)$;\5
$\\{skew\_line\_edges}(\\{xx1},\39\\{yy1},\39\\{x\_coord}(\|q)+\\{x\_coord}(%
\\{ww}),\39\\{y\_coord}(\|q)+\\{y\_coord}(\\{ww}),\39\\{octant})$;\6
\&{end}\2\par
\U section~453.\fi

\N459.  \[xx] Elliptical pens.
To get the envelope of a cyclic path with respect to an ellipse, \MF\
calculates the envelope with respect to a polygonal approximation to
the ellipse, using an approach due to John Hobby [to appear].
This has two important advantages over trying to obtain the ``exact''
envelope:

\yskip\textindent{1)}It gives better results, because the polygon has been
designed to counteract problems that arise from digitization; the
polygon includes sub-pixel corrections to an exact ellipse that make
the results essentially independent of where the path falls on the raster.
For example, the exact envelope with respect to a pen of diameter~1
blackens a pixel if and only if the path intersects a circle of diameter~1
inscribed in that pixel; the resulting pattern has ``blots'' when the path
is travelling diagonally in unfortunate raster positions. A much better
result is obtained when pixels are blackened only when the path intersects
an inscribed {\sl diamond\/} of diameter~1. Such a diamond is precisely
the polygon \MF\ uses in the special case of a circle whose diameter is~1.

\yskip\textindent{2)}Polygonal envelopes of cubic splines are cubic
splines, hence it isn't necessary to introduce completely different
routines. By contrast, exact envelopes of cubic splines with respect
to circles are complicated curves, more difficult to plot than cubics.

\fi

\M460. Hobby's construction involves some interesting number theory.
If $u$ and~$v$ are are relatively prime integers, we divide the
set of integer points $(m,n)$ into equivalence classes by saying
that $(m,n)$ belongs to class $um+vn$. Then any two integer points
that lie on a line of slope $-u/v$ belong to the same class, because
such points have the form $(m+tv,n-tu)$. Neighboring lines of slope $-u/v$
that go through integer points are separated by distance $1/\sqrt{u↑2+v↑2}$
from each other, and these lines are perpendicular to lines of slope~$v/u$.
If we start at the origin and travel a distance $k/\sqrt{u↑2+v↑2}$ in
direction $(u,v)$, we reach the line of slope~$-u/v$ whose points
belong to class~$k$.

For example, let $u=2$ and $v=3$. Then the points $(0,0)$, $(3,-2)$,
$\ldots$ belong to class~0; the points $(-1,1)$, $(2,-1)$, $\ldots$ belong
to class~1; and the distance between these two lines is $1/\sqrt{13}$.
The point $(2,3)$ itself belongs to class~13, hence its distance from
the origin is $\sqrt{13}$ (which we already knew).

Suppose we wish to plot envelopes with respect to polygons with
integer vertices. Then the best polygon for curves that travel in
direction $(v,-u)$ will contain the points of class~$k$ such that
$k/\sqrt{u↑2+v↑2}$ is as close as possible to~$d$, where $d$ is the
maximum distance of the given ellipse from the line $ux+vy=0$.

Integer coordinates for the vertices work nicely because the thickness of
the envelope at any given slope is independent of the position of the
path with respect to the raster. It turns out, in fact, that the same
property holds for polygons whose vertices have coordinates that are
integer multiples of~$1\over2$, because ellipses are symmetric about
the origin. It's convenient to double all dimensions and require the
resulting polygon to have vertices with integer coordinates. For example,
to get a circle of {\sl diameter}~$r$, we shall compute integer
coordinates for a circle of {\sl radius}~$r$. The circle of radius~$r$
will want to be represented by a polygon that contains the boundary
points $(0,\pm r)$ and~$(\pm r,0)$; later we will divide everything
by~2 and get a polygon with $(0,\pm{1\over2}r)$ and $(\pm{1\over2}r,0)$
on its boundary.

\fi

\M461. In practice the important slopes are those having small values of
$u$ and~$v$; these make regular patterns in which our eyes quickly
spot irregularities. For example, horizontal and vertical lines
(when $u=0$ and $\vert v\vert=1$ or $\vert u\vert=1$ and $v=0$)
are the most important; diagonal lines (when $\vert u\vert=\vert v\vert=1$)
are next; and then come lines with slope $\pm2$ or $\pm1/2$.

The nicest way to generate all rational directions having small
numerators and denominators is to generalize the Stern-Peirce tree
[cf.~{\sl The Art of Computer Programming\/ \bf2}, exercise 4.5.3--40]
to a ``Stern-Peirce wreath'' as follows: Begin with four nodes
arranged in a circle, containing the respective directions
$(u,v)=(1,0)$, $(0,1)$, $(-1,0)$, and~$(0,-1)$. Then between pairs of
consecutive terms $(u,v)$ and $(u',v')$ of the wreath, insert the
direction $(u+u',v+v')$; continue doing this until some stopping
criterion is fulfilled.

It is not difficult to verify that, regardless of the stopping
criterion, consecutive directions $(u,v)$ and $(u',v')$ of this
wreath will always satisfy the relation $uv'-u'v=1$. Such pairs
of directions have a nice property with respect to the equivalence
classes described above. Let $l$ be a line of equivalent integer points
$(m+tv,n-tu)$ with respect to~$(u,v)$, and let $l'$ be a line of
equivalent integer points $(m'+tv',n'-tu')$ with respect to~$(u',v')$.
Then $l$ and~$l'$ intersect in an integer point $(m'',n'')$, because
the determinant of the linear equations for intersection is $uv'-vu'=1$.
Notice that the class number of $(m'',n'')$ with respect to $(u+u',v+v')$
is the sum of its class numbers with respect to $(u,v)$ and~$(u',v')$.
Moreover, consecutive points on~$l$ and~$l'$ belong to classes that
differ by exactly~1 with respect to $(u+u',v+v')$.

This leads to a nice algorithm in which we construct a polygon having
``correct'' class numbers for as many small-integer directions $(u,v)$
as possible: Assuming that lines $l$ and~$l'$ contain points of the
correct class for $(u,v)$ and~$(u',v')$, respectively, we determine
the intersection $(m'',n'')$ and compute its class with respect to
$(u+u',v+v')$. If the class is too large to be the best approximation,
we move back the proper number of steps from $(m'',n'')$ toward smaller
class numbers
on both $l$ and~$l'$, unless this requires moving to points that
are no longer in the polygon; these two points will determine a line~$l''$
having the appropriate class. The process continues recursively,
until it cannot proceed without removing the last remaining point
from the class for $(u,v)$ or the class for $(u',v')$.

\fi

\M462. The \\{make\_ellipse} subroutine produces a pointer to a cyclic path
whose vertices define a polygon suitable for envelopes. The control
points on this path will be ignored; in fact, the fields in knot nodes
that are usually reserved for control points are occupied by other
data that helps \\{make\_ellipse} compute the desired polygon.

Parameters \\{major\_axis} and \\{minor\_axis} define the axes of the ellipse;
and parameter \\{theta} is an angle by which the ellipse is rotated
counterclockwise. If $\\{theta}=0$, the ellipse has the equation
$(x/a)↑2+(y/b)↑2=1$, where $\|a=\\{major\_axis}/2$ and $\|b=\\{minor\_axis}/2$.
In general, the points of the ellipse are generated in the complex plane
by the formula $e↑{i\theta}(a\cos t+ib\sin t)$, as $t$~ranges over all
angles. Notice that if $\\{major\_axis}=\\{minor\_axis}=\|d$, we obtain a
circle
of diameter~\|d, regardless of the value of \\{theta}.

The method sketched above is used to produce the elliptical polygon,
except that the main work is done only in the halfplane obtained from
the three starting points $(0,-1)$, $(1,0)$,~$(0,1)$. Since the ellipse
has circular symmetry, we use the fact that the last half of the polygon
is simply the negative of the first half.

\Y\P\4\&{function}\1\  \37$\\{make\_ellipse}(\\{major\_axis},\39\\{minor%
\_axis}:\\{scaled};\,\35\\{theta}:\\{angle})$: \37\\{pointer};\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list
manipulation}\6
\|h: \37\\{pointer};\C{head of the constructed knot list}\6
$\\{alpha},\39\\{beta},\39\\{gamma},\39\\{delta}$: \37\\{integer};\C{special
points}\6
$\|c,\39\|d$: \37\\{integer};\C{class numbers}\6
$\|u,\39\|v$: \37\\{integer};\C{directions}\2\6
\&{begin} \37\X463:Initialize the ellipse data structure by beginning with
directions $(0,-1)$, $(1,0)$, $(0,1)$\X;\6
\X465:Interpolate new vertices in the ellipse data structure until improvement
is impossible\X;\6
\X471:Complete the ellipse by copying the negative of the half already computed%
\X;\6
$\\{make\_ellipse}\K\|h$;\6
\&{end};\par
\fi

\M463. A special data structure is used only with \\{make\_ellipse}: The
\\{right\_x}, \\{left\_x}, \\{right\_y}, and \\{left\_y} fields of knot nodes
are renamed \\{right\_u}, \\{left\_v}, \\{right\_class}, and \\{left\_length},
in order to simplify the computation that \\{make\_ellipse} must perform.

If \|p and \|q are consecutive knots in this data structure, the
\\{x\_coord} and \\{y\_coord} fields of \|p and~\|q contain current vertices
of the polygon; their values are integer multiples of $1\over2$, i.e.,
of \\{half\_unit}. Both of these vertices belong to equivalence class
$\\{right\_class}(\|p)$ with respect to the direction
$\bigl($$\\{right\_u}(\|p),\\{left\_v}(\|q)$$\bigr)$. The number of points of
this class
on the line from vertex~\|p to vertex~\|q is $1+\\{left\_length}(\|q)$.
In particular, $\\{left\_length}(\|q)=0$ means that $\\{x\_coord}(\|p)=\\{x%
\_coord}(\|q)$
and $\\{y\_coord}(\|p)=\\{y\_coord}(\|q)$; such duplicate vertices will be
discarded during the course of the algorithm.

The contents of $\\{right\_u}(\|p)$ and $\\{left\_v}(\|q)$ are integer
multiples
of \\{half\_unit}, just like the coordinate fields. Hence, for example,
the point $\bigl($$\\{x\_coord}(\|p)-\\{left\_v}(\|q),\\{y\_coord}(\|p)+%
\\{right\_u}(\|q)$$\bigr)$
also belongs to class number $\\{right\_class}(\|p)$. This point is one
step closer to the vertex in node~\|q; it equals that vertex
if and only if $\\{left\_length}(\|q)=1$.

The \\{left\_type} and \\{right\_type} fields are not used, but \\{link}
has its normal meaning.

To start the process, we create four nodes for the three directions
$(0,-1)$, $(1,0)$, and $(0,1)$. The corresponding vertices are
$(-\alpha,-\beta)$, $(\gamma,-\beta)$, $(\gamma,\beta)$, and
$(\alpha,\beta)$, where $(\alpha,\beta)$ is a half-integer approximation
to where the ellipse rises highest above the $x$-axis, and where
$\gamma$ is a half-integer approximation to the maximum $x$-coordinate
of the ellipse.

\Y\P$\4\X463:Initialize the ellipse data structure by beginning with directions
$(0,-1)$, $(1,0)$, $(0,1)$\X\S$\6
$\|p\K\\{get\_node}(\\{knot\_size})$;\5
$\|q\K\\{get\_node}(\\{knot\_size})$;\5
$\|r\K\\{get\_node}(\\{knot\_size})$;\5
$\|s\K\\{get\_node}(\\{knot\_size})$;\6
$\|h\K\|p$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{link}(\|q)\K\|r$;\5
$\\{link}(\|r)\K\|s$;\C{$\\{link}(\|s)=\\{null}$}\6
\X464:Calculate integers $\alpha$, $\beta$, $\gamma$ for the vertex coordinates%
\X;\6
\&{if} $\\{beta}=0$ \1\&{then}\5
$\\{beta}\K1$;\C{avoid degenerate lines of length zero}\2\6
\&{if} $\\{gamma}\L\\{abs}(\\{alpha})$ \1\&{then}\5
$\\{gamma}\K\\{abs}(\\{alpha})+1$;\2\6
$\\{x\_coord}(\|s)\K\\{alpha}\ast\\{half\_unit}$;\5
$\\{x\_coord}(\|p)\K-\\{x\_coord}(\|s)$;\6
$\\{y\_coord}(\|s)\K\\{beta}\ast\\{half\_unit}$;\5
$\\{y\_coord}(\|p)\K-\\{y\_coord}(\|s)$;\6
$\\{y\_coord}(\|q)\K\\{y\_coord}(\|p)$;\5
$\\{y\_coord}(\|r)\K\\{y\_coord}(\|s)$;\6
$\\{x\_coord}(\|q)\K\\{gamma}\ast\\{half\_unit}$;\5
$\\{x\_coord}(\|r)\K\\{x\_coord}(\|q)$;\6
$\\{right\_u}(\|p)\K0$;\5
$\\{left\_v}(\|q)\K-\\{half\_unit}$;\6
$\\{right\_u}(\|q)\K\\{half\_unit}$;\5
$\\{left\_v}(\|r)\K0$;\6
$\\{right\_u}(\|r)\K0$;\5
$\\{left\_v}(\|s)\K\\{half\_unit}$;\6
$\\{right\_class}(\|p)\K\\{beta}$;\5
$\\{right\_class}(\|q)\K\\{gamma}$;\5
$\\{right\_class}(\|r)\K\\{beta}$;\6
$\\{left\_length}(\|q)\K\\{gamma}+\\{alpha}$;\5
$\\{left\_length}(\|r)\K\\{beta}+\\{beta}$;\5
$\\{left\_length}(\|s)\K\\{gamma}-\\{alpha}$\par
\U section~462.\fi

\M464. If $a$ and $b$ are the semi-major and semi-minor axes,
the given ellipse rises highest above the $y$-axis at the point
$(a↑2-b↑2)\sin\theta\cos\theta/\rho+i\rho$, where
$\rho=\sqrt{(a\sin\theta)↑2+(b\cos\theta)↑2}$. It reaches
furthest to the right of the $x$-axis at the point
$\sigma+i(a↑2-b↑2)\sin\theta\cos\theta/\sigma$, where
$\sigma=\sqrt{(a\cos\theta)↑2+(b\sin\theta)↑2}$.

\Y\P$\4\X464:Calculate integers $\alpha$, $\beta$, $\gamma$ for the vertex
coordinates\X\S$\6
\&{if} $(\\{theta}=0)\V(\\{major\_axis}=\\{minor\_axis})$ \1\&{then}\6
\&{begin} \37$\\{alpha}\K0$;\5
$\\{beta}\K\\{minor\_axis}$;\5
$\\{gamma}\K\\{major\_axis}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{n\_sin\_cos}(\\{theta})$;\C{set up $\\{n\_sin}=\sin%
\theta$ and 		$\\{n\_cos}=\cos\theta$}\6
$\\{gamma}\K\\{take\_fraction}(\\{major\_axis},\39\\{n\_sin})$;\5
$\\{delta}\K\\{take\_fraction}(\\{minor\_axis},\39\\{n\_cos})$;\5
$\\{beta}\K\\{pyth\_add}(\\{gamma},\39\\{delta})$;\5
$\\{alpha}\K\\{take\_fraction}(\\{take\_fraction}(\\{major\_axis},\39\\{make%
\_fraction}(\\{gamma},\39\\{beta})),\39\\{n\_cos})\30-\\{take\_fraction}(%
\\{take\_fraction}(\\{minor\_axis},\39\\{make\_fraction}(\\{delta},\39%
\\{beta})),\39\\{n\_sin})$;\5
$\\{alpha}\K(\\{alpha}+\\{half\_unit})\mathbin{\&{div}}\\{unity}$;\5
$\\{gamma}\K\\{pyth\_add}(\\{take\_fraction}(\\{major\_axis},\39\\{n\_cos}),\39%
\\{take\_fraction}(\\{minor\_axis},\39\\{n\_sin}))$;\6
\&{end};\2\6
$\\{beta}\K(\\{beta}+\\{half\_unit})\mathbin{\&{div}}\\{unity}$;\5
$\\{gamma}\K(\\{gamma}+\\{half\_unit})\mathbin{\&{div}}\\{unity}$\par
\U section~463.\fi

\M465. Now \|p, \|q, and \|r march through the list, always representing
three consecutive vertices and two consecutive slope directions.
When a new slope is interpolated, we back up slightly, until
further refinement is impossible; then we march forward again.
The somewhat magical operations performed in this part of the
algorithm are justified by the theory sketched earlier.
Complications arise only from the need to keep zero-length lines
out of the data structure.

\Y\P$\4\X465:Interpolate new vertices in the ellipse data structure until
improvement is impossible\X\S$\6
\1\&{repeat} \37$\|u\K\\{right\_u}(\|p)+\\{right\_u}(\|q)$;\5
$\|v\K\\{left\_v}(\|q)+\\{left\_v}(\|r)$;\5
$\|c\K\\{right\_class}(\|p)+\\{right\_class}(\|q)$;\5
\X466:Compute the distance \|d from class~0 to the edge of the ellipse in
direction $(\|u,\|v)$, times $\sqrt{u↑2+v↑2}$, rounded to the nearest integer%
\X;\6
$\\{delta}\K\|c-\|d$;\C{we want to move \\{delta} steps back 		from the
intersection vertex~\|q}\6
\&{if} $\\{delta}>0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{delta}>\\{left\_length}(\|r)$ \1\&{then}\5
$\\{delta}\K\\{left\_length}(\|r)$;\2\6
\&{if} $\\{delta}\G\\{left\_length}(\|q)$ \1\&{then}\5
\X467:Remove the line from \|p to \|q, and adjust vertex~\|q to introduce a new
line\X\6
\4\&{else} \&{if} $\\{delta}=\\{left\_length}(\|r)$ \1\&{then}\5
\X468:Remove the line from \|q to \|r, and adjust vertex~\|q to introduce a new
line\X\6
\4\&{else} \X470:Insert a new line for direction $(\|u,\|v)$ between \|p and~%
\|q\X;\2\2\6
\&{end}\6
\4\&{else} $\|p\K\|q$;\2\6
$\|q\K\\{link}(\|p)$;\5
$\|r\K\\{link}(\|q)$;\6
\4\&{until}\5
$(\|q=\\{null})\V(\|r=\\{null})$\2\par
\U section~462.\fi

\M466. The `\ignorespaces$\mathbin{\&{div}}8$\unskip' near the end of this step
comes from
the fact that \\{delta} is scaled by~$2↑{15}$ and $d$~by~$2↑{16}$,
while \\{take\_fraction} removes a scale factor of~$2↑{28}$.
We also make sure that $d\G\max(\vert u\vert,\vert v\vert)$, so that
the pen will always include a circular pen of diameter~1 as a subset;
then it won't be possible to get disconnected path envelopes.

\Y\P$\4\X466:Compute the distance \|d from class~0 to the edge of the ellipse
in direction $(\|u,\|v)$, times $\sqrt{u↑2+v↑2}$, rounded to the nearest
integer\X\S$\6
$\\{delta}\K\\{pyth\_add}(\|u,\39\|v)$;\6
\&{if} $\\{major\_axis}=\\{minor\_axis}$ \1\&{then}\5
$\|d\K\\{major\_axis}$\C{circles are easy}\6
\4\&{else} \&{begin} \37\&{if} $\\{theta}=0$ \1\&{then}\6
\&{begin} \37$\\{alpha}\K\|u$;\5
$\\{beta}\K\|v$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{alpha}\K\\{take\_fraction}(\|u,\39\\{n\_cos})+%
\\{take\_fraction}(\|v,\39\\{n\_sin})$;\5
$\\{beta}\K\\{take\_fraction}(\|v,\39\\{n\_cos})-\\{take\_fraction}(\|u,\39\\{n%
\_sin})$;\6
\&{end};\2\6
$\\{alpha}\K\\{make\_fraction}(\\{alpha},\39\\{delta})$;\5
$\\{beta}\K\\{make\_fraction}(\\{beta},\39\\{delta})$;\5
$\|d\K\\{pyth\_add}(\\{take\_fraction}(\\{major\_axis},\39\\{alpha}),\39\\{take%
\_fraction}(\\{minor\_axis},\39\\{beta}))$;\6
\&{end};\2\6
$\|d\K\\{take\_fraction}((\|d+4)\mathbin{\&{div}}8,\39\\{delta})$;\6
\&{if} $\\{abs}(\|u)\G\\{abs}(\|v)$ \1\&{then}\5
$\\{alpha}\K\\{abs}(\|u)\mathbin{\&{div}}\\{half\_unit}$\ \&{else} $\\{alpha}\K%
\\{abs}(\|v)\mathbin{\&{div}}\\{half\_unit}$;\2\6
\&{if} $\|d<\\{alpha}$ \1\&{then}\5
$\|d\K\\{alpha}$\2\par
\U section~465.\fi

\M467. At this point there's a line of length $\L\\{delta}$ from vertex~\|p
to vertex~\|q, orthogonal to direction $\bigl($$\\{right\_u}(\|p),\\{left\_v}(%
\|q)$$\bigr)$;
and there's a line of length $\G\\{delta}$ from vertex~\|q to
to vertex~\|r, orthogonal to direction $\bigl($$\\{right\_u}(\|q),\\{left\_v}(%
\|r)$$\bigr)$.
The best line to direction $(u,v)$ should replace the line from
\|p to~\|q; this new line will have the same length as the old.

The transformation in this step might move vertex~\|q allthe way over to
vertex~\|r, in which case we remove node~\|r.

\Y\P$\4\X467:Remove the line from \|p to \|q, and adjust vertex~\|q to
introduce a new line\X\S$\6
\&{begin} \37$\\{delta}\K\\{left\_length}(\|q)$;\6
$\\{right\_class}(\|p)\K\|c-\\{delta}$;\5
$\\{right\_u}(\|p)\K\|u$;\6
\&{if} $\\{left\_length}(\|r)>\\{delta}$ \1\&{then}\6
\&{begin} \37$\\{left\_v}(\|q)\K\|v$;\6
$\\{x\_coord}(\|q)\K\\{x\_coord}(\|q)-\\{delta}\ast\\{left\_v}(\|r)$;\5
$\\{y\_coord}(\|q)\K\\{y\_coord}(\|q)+\\{delta}\ast\\{right\_u}(\|q)$;\6
$\\{left\_length}(\|r)\K\\{left\_length}(\|r)-\\{delta}$;\6
\&{end}\6
\4\&{else} \X469:Remove and move past the line from \|q to \|r\X;\2\6
\&{end}\par
\U section~465.\fi

\M468. This case is dual to the previous one: A line now disappears at the
right of the new line instead of at the left. When a line is removed
at the right, we need to advance~\|p, because the algorithm works
only on consecutive pairs of directions; we must not try to straddle
a missing direction.

\Y\P$\4\X468:Remove the line from \|q to \|r, and adjust vertex~\|q to
introduce a new line\X\S$\6
\&{begin} \37$\\{right\_class}(\|q)\K\|c-\\{delta}$;\5
$\\{right\_u}(\|q)\K\|u$;\5
$\\{left\_v}(\|r)\K\|v$;\6
$\\{x\_coord}(\|q)\K\\{x\_coord}(\|q)+\\{delta}\ast\\{left\_v}(\|q)$;\5
$\\{y\_coord}(\|q)\K\\{y\_coord}(\|q)-\\{delta}\ast\\{right\_u}(\|p)$;\6
$\\{left\_length}(\|q)\K\\{left\_length}(\|q)-\\{delta}$;\5
$\|p\K\|r$;\6
\&{end}\par
\U section~465.\fi

\M469. \P$\X469:Remove and move past the line from \|q to \|r\X\S$\6
\&{begin} \37$\\{link}(\|p)\K\|r$;\5
$\\{left\_v}(\|r)\K\|v$;\5
$\\{left\_length}(\|r)\K\\{delta}$;\6
$\\{free\_node}(\|q,\39\\{knot\_size})$;\5
$\|p\K\|r$;\6
\&{end}\par
\U section~467.\fi

\M470. And here is the main case, now that we have dealt with the exceptions:
We insert a new line of length \\{delta} for direction $(\|u,\|v)$, decreasing
each of the adjacent lines by \\{delta} steps.

\Y\P$\4\X470:Insert a new line for direction $(\|u,\|v)$ between \|p and~\|q\X%
\S$\6
\&{begin} \37$\|s\K\\{get\_node}(\\{knot\_size})$;\5
$\\{link}(\|p)\K\|s$;\5
$\\{link}(\|s)\K\|q$;\6
$\\{x\_coord}(\|s)\K\\{x\_coord}(\|q)+\\{delta}\ast\\{left\_v}(\|q)$;\5
$\\{y\_coord}(\|s)\K\\{y\_coord}(\|q)-\\{delta}\ast\\{right\_u}(\|p)$;\6
$\\{x\_coord}(\|q)\K\\{x\_coord}(\|q)-\\{delta}\ast\\{left\_v}(\|r)$;\5
$\\{y\_coord}(\|q)\K\\{y\_coord}(\|q)+\\{delta}\ast\\{right\_u}(\|q)$;\6
$\\{left\_v}(\|s)\K\\{left\_v}(\|q)$;\5
$\\{right\_u}(\|s)\K\|u$;\5
$\\{left\_v}(\|q)\K\|v$;\6
$\\{right\_class}(\|s)\K\|c-\\{delta}$;\6
$\\{left\_length}(\|p)\K\\{left\_length}(\|p)-\\{delta}$;\5
$\\{left\_length}(\|s)\K\\{delta}$;\5
$\\{left\_length}(\|q)\K\\{left\_length}(\|q)-\\{delta}$;\6
\&{end}\par
\U section~465.\fi

\M471. Now we use a somewhat tricky fact: The pointer \|q will be null if and
only if the line for the final direction $(0,1)$ has been removed. If
that line still survives, it should be combined with a possibly
surviving line in the initial direction~$(0,-1)$.

Only the coordinates need to be copied, not the class numbers and other stuff.

\Y\P$\4\X471:Complete the ellipse by copying the negative of the half already
computed\X\S$\6
\&{if} $\|q\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{right\_u}(\|h)=0$ \1\&{then}\6
\&{begin} \37$\|p\K\|h$;\5
$\|h\K\\{link}(\|h)$;\5
$\\{free\_node}(\|p,\39\\{knot\_size})$;\6
$\\{x\_coord}(\|q)\K-\\{x\_coord}(\|h)$;\6
\&{end};\2\6
$\|p\K\|q$;\6
\&{end}\6
\4\&{else} $\|q\K\|p$;\2\6
$\|r\K\\{link}(\|h)$;\C{now $\|p=\|q$, $\\{x\_coord}(\|p)=-\\{x\_coord}(\|h)$,
$\\{y\_coord}(\|p)=-\\{y\_coord}(\|h)$}\6
\1\&{repeat} \37$\|s\K\\{get\_node}(\\{knot\_size})$;\5
$\\{link}(\|p)\K\|s$;\5
$\|p\K\|s$;\6
$\\{x\_coord}(\|p)\K-\\{x\_coord}(\|r)$;\5
$\\{y\_coord}(\|p)\K-\\{y\_coord}(\|r)$;\5
$\|r\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|r=\|q$;\2\6
$\\{link}(\|p)\K\|h$\par
\U section~462.\fi

\N472.  \[xx] Online graphic output.
\MF\ displays images on the user's screen by means of a few primitive
operations that are defined below. These operations have deliberately been
kept simple so that they can be implemented without great difficulty on a
wide variety of machines. Since \PASCAL\ has no traditional standards for
graphic output, some system-dependent code needs to be written in order to
support this aspect of \MF; but the necessary routines are usually quite
easy to write.

In fact, there are exactly four such routines:

\yskip
\textindent{\\{init\_screen}} does whatever initialization is necessary to
support the other operations; it is a boolean function that returns
\\{false} if graphic output cannot be supported (e.g., if the other three
routines have not been written, or if the user doesn't have the
right kind of terminal).

\yskip
\textindent{\\{blank\_rectangle}} updates a buffer area in memory so that
all pixels in a specified rectangle will be set to the background color.

\yskip
\textindent{\\{paint\_row}} assigns values to specified pixels in a row of
the buffer just mentioned, based on ``transition'' indices explained below.

\yskip
\textindent{\\{update\_screen}} displays the current screen buffer; the
effects of \\{blank\_rectangle} and \\{paint\_row} commands may or may not
become visible until the next \\{update\_screen} operation is performed.
(Thus, \\{update\_screen} is analogous to \\{update\_terminal}.)

\yskip\noindent
The \PASCAL\ code here is a minimum version of \\{init\_screen} and
\\{update\_screen}, usable on \MF\ installations that don't
support screen output.

\Y\P\4\&{function}\1\  \37\\{init\_screen}: \37\\{boolean};\2\6
\&{begin} \37$\\{init\_screen}\K\\{false}$;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{update\_screen};\C{will be called only if \\{init%
\_screen} returns \\{true}}\2\6
\&{begin} \37$\\{confusion}(\.{"u"})$;\6
\&{end};\par
\fi

\M473. The user's screen is assumed to be a rectangular area, \\{screen\_width}
pixels wide and \\{screen\_depth} pixels deep. The pixel in the upper left
corner is said to be in column~0 of row~0; the pixel in the lower right
corner is said to be in column $\\{screen\_width}-1$ of row $\\{screen%
\_depth}-1$.
Notice that row numbers increase from top to bottom, contrary to \MF's
other coordinates.

Each pixel is assumed to have two states, referred to in this documentation
as \\{black} and \\{white}. The background color is called \\{white} and the
other color is called \\{black}; but any two distinct pixel values
can actually be used. For example, the author developed \MF\ on a
system for which \\{white} was black and \\{black} was bright green.

\Y\P\D \37$\\{white}=0$\C{background pixels}\par
\P\D \37$\\{black}=1$\C{visible pixels}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{screen\_row}=0\to\\{screen\_depth}$;\C{a row number on the screen}\6
$\\{screen\_col}=0\to\\{screen\_width}$;\C{a column number on the screen}\6
$\\{trans\_spec}=$\1\5
\&{array} $[\\{screen\_row}]$ \1\&{of}\5
\\{screen\_col};\C{a transition spec, see below}\2\2\6
$\\{pixel\_color}=\\{white}\to\\{black}$;\C{specifies one of the two pixel
values}\par
\fi

\M474. We'll illustrate the \\{blank\_rectangle} and \\{paint\_row} operations
by
pretending to declare a screen buffer called \\{screen\_pixel}. This code
is actually commented out, but it does specify the intended effects.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\B\\{screen\_pixel}$: \37\&{array} $[\\{screen\_row},\39\\{screen\_col}]$ \1%
\&{of}\5
\\{pixel\_color};\2\6
$\T$\par
\fi

\M475. The \\{blank\_rectangle} routine simply whitens all pixels that lie in
columns \\{left\_col} through $\\{right\_col}-1$, inclusive, of rows
\\{top\_row} through $\\{bot\_row}-1$, given four parameters that satisfy
the relations
$$\hbox{$0\L\\{left\_col}\L\\{right\_col}\L\\{screen\_width}$,\quad
$0\L\\{top\_row}\L\\{bot\_row}\L\\{screen\_depth}$.}$$
If $\\{left\_col}=\\{right\_col}$ or $\\{left\_row}=\\{right\_row}$, nothing
happens.

The commented-out code in the following procedure is for illustrative
purposes only.

\Y\P\4\&{procedure}\1\  \37$\\{blank\_rectangle}(\\{left\_col},\39\\{right%
\_col}:\\{screen\_col};\,\35\\{top\_row},\39\\{bot\_row}:\\{screen\_row})$;\6
\4\&{var} \37\|r: \37\\{screen\_row};\5
\|c: \37\\{screen\_col};\2\6
\&{begin} \37$\B$\1\6
\&{for} $\|r\K\\{top\_row}\mathrel{\&{to}}\\{bot\_row}-1$ \1\&{do}\6
\&{for} $\|c\K\\{left\_col}\mathrel{\&{to}}\\{right\_col}-1$ \1\&{do}\5
$\\{screen\_pixel}[\|r,\39\|c]\K\\{white}$;\2\2\2\6
$\T\\{confusion}(\.{"b"})$;\C{\\{blank\_rectangle} is called only after $%
\\{init\_screen}=\\{true}$}\6
\&{end};\par
\fi

\M476. The real work of screen display is done by \\{paint\_row}. But it's not
hard work, because the operation affects only
one of the screen rows, and only a contiguous set of columns
in that row. There are four parameters: \|r~(the row),
\|b~(the initial color),
\|a~(the array of transition specifications),
and \|n~(the number of transitions). The elements of~\|a will satisfy
$$0\L a[0]<a[1]<\cdots<a[n]\L \\{screen\_width};$$
the value of \|r will satisfy $0\L\|r<\\{screen\_depth}$; and \|n will be
positive.

The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\
program (see the commented-out code below).

\Y\P\4\&{procedure}\1\  \37$\\{paint\_row}(\|r:\\{screen\_row};\,\35\|b:%
\\{pixel\_color};\,\35\mathop{\&{var}}\|a:\\{trans\_spec};\,\35\|n:\\{screen%
\_col})$;\6
\4\&{var} \37\|k: \37\\{screen\_col};\C{an index into \|a}\6
\|c: \37\\{screen\_col};\C{an index into \\{screen\_pixel}}\2\6
\&{begin} \37$\B\|k\K0$;\5
$\|c\K\|a[0]$;\6
\1\&{repeat} \37$\\{incr}(\|k)$;\6
\1\&{repeat} \37$\\{screen\_pixel}[\|r,\39\|c]\K\|b$;\5
$\\{incr}(\|c)$;\6
\4\&{until}\5
$\|c=\|a[\|k]$;\2\6
$\|b\K\\{black}-\|b$;\C{$\\{black}\swap\\{white}$}\6
\4\&{until}\5
$\|k=\|n$;\2\6
$\T\\{confusion}(\.{"p"})$;\C{\\{paint\_row} is called only after $\\{init%
\_screen}=\\{true}$}\6
\&{end};\par
\fi

\M477. The remainder of \MF's screen routines are system-independent calls
on the four primitives just defined.

First we have a global boolean variable that tells if \\{init\_screen}
has been called, and another one that tells if \\{init\_screen} has
given a \\{true} response.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{screen\_started}: \37\\{boolean};\C{have the screen primitives been
initialized?}\6
\4\\{screen\_OK}: \37\\{boolean};\C{is it legitimate to call \\{blank%
\_rectangle}, 	\\{paint\_row}, and \\{update\_screen}?}\par
\fi

\M478. \P\D \37$\\{start\_screen}\S$\1\6
\&{begin} \37\&{if} $\R\\{screen\_started}$ \1\&{then}\5
$\\{screen\_OK}\K\\{init\_screen}$;\2\6
\&{end}\2\par
\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{screen\_started}\K\\{false}$;\5
$\\{screen\_OK}\K\\{false}$;\par
\fi

\M479. \MF\ provides the user with 16 ``window'' areas on the screen, in each
of which it is possible to produce independent displays.

It should be noted that \MF's windows aren't really independent
``clickable'' entities in the sense of multi-window graphic workstations;
\MF\ simply maps them into subsets of a single screen image that is
controlled by \\{init\_screen}, \\{blank\_rectangle}, \\{paint\_row}, and
\\{update\_screen} as described above. Implementations of \MF\ on a
multi-window workstation probably therefore make use of only two
windows in the other sense: one for the terminal output and another
for the screen with \MF's 16 areas. Henceforth we shall
use the term window only in \MF's sense.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{window\_number}=0\to15$;\par
\fi

\M480. A user doesn't have to use any of the 16 windows. But when a window is
``opened,'' it is allocated to a specific rectangular portion of the screen
and to a specific rectangle with respect to \MF's coordinates. The relevant
data is stored in global arrays \\{window\_open}, \\{left\_col}, \\{right%
\_col},
\\{top\_row}, \\{bot\_row}, \\{m\_window}, and \\{n\_window}.

The \\{window\_open} array is boolean, and its significance is obvious. The
\\{left\_col}, \dots, \\{bot\_row} arrays contain screen coordinates that
can be used to blank the entire window with \\{blank\_rectangle}. And the
other two arrays just mentioned handle the conversion between
actual coordinates and screen coordinates: \MF's pixel in column~$m$
of row~$n$ will appear in screen column $\\{m\_window}+\|m$ and screen row
$\\{n\_window}-\|n$, provided that these lie inside the boundaries of the
window.

Another array \\{window\_time} holds the number of times this window has
been updated.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{window\_open}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{boolean};\C{has this window been opened?}\2\6
\4\\{left\_col}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{screen\_col};\C{leftmost column position on screen}\2\6
\4\\{right\_col}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{screen\_col};\C{rightmost column position, plus~1}\2\6
\4\\{top\_row}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{screen\_row};\C{topmost row position on screen}\2\6
\4\\{bot\_row}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{screen\_row};\C{bottommost row position, plus~1}\2\6
\4\\{m\_window}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{integer};\C{offset between user and screen columns}\2\6
\4\\{n\_window}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{integer};\C{offset between user and screen rows}\2\6
\4\\{window\_time}: \37\&{array} $[\\{window\_number}]$ \1\&{of}\5
\\{integer};\C{it has been updated this often}\2\par
\fi

\M481. \P$\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}%
\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}15$ \1\&{do}\6
\&{begin} \37$\\{window\_open}[\|k]\K\\{false}$;\5
$\\{window\_time}[\|k]\K0$;\6
\&{end};\2\par
\fi

\M482. Opening a window isn't like opening a file, because you can open it
as often as you like, and you never have to close it again. The idea is
simply to define special points on the current screen display.

Overlapping window specifications may cause complex effects that can
be understood only by scrutinizing \MF's display algorithms; thus it
has been left undefined in the \MF\ user manual, although the behavior
is in fact predictable.

Here is a subroutine that implements the command `\&{openwindow}~\|k
\&{from}~$(\\{r0},\\{c0})$ \&{to}~$(\\{r1},\\{c1})$ \&{at}~$(x,y)$'.

\Y\P\4\&{procedure}\1\  \37$\\{open\_window}(\|k:\\{window\_number};\,\35%
\\{r0},\39\\{c0},\39\\{r1},\39\\{c1}:\\{integer};\,\35\|x,\39\|y:\\{scaled})$;%
\2\6
\&{begin} \37\X483:Adjust the coordinates $(\\{r0},\\{c0})$ and $(\\{r1},%
\\{c1})$ so that they lie in the proper range\X;\6
$\\{window\_open}[\|k]\K\\{true}$;\5
$\\{incr}(\\{window\_time}[\|k])$;\6
$\\{left\_col}[\|k]\K\\{c0}$;\5
$\\{right\_col}[\|k]\K\\{c1}$;\5
$\\{top\_row}[\|k]\K\\{r0}$;\5
$\\{bot\_row}[\|k]\K\\{r1}$;\6
\X484:Compute the offsets between screen coordinates and actual coordinates\X;\6
\\{start\_screen};\6
\&{if} $\\{screen\_OK}$ \1\&{then}\6
\&{begin} \37$\\{blank\_rectangle}(\\{c0},\39\\{c1},\39\\{r0},\39\\{r1})$;\5
\\{update\_screen};\6
\&{end};\2\6
\&{end};\par
\fi

\M483. A window whose coordinates don't fit the existing screen size will be
truncated until they do.

\Y\P$\4\X483:Adjust the coordinates $(\\{r0},\\{c0})$ and $(\\{r1},\\{c1})$ so
that they lie in the proper range\X\S$\6
\&{if} $\\{r0}<0$ \1\&{then}\5
$\\{r0}\K0$;\2\6
\&{if} $\\{r1}>\\{screen\_depth}$ \1\&{then}\5
$\\{r1}\K\\{screen\_depth}$;\2\6
\&{if} $\\{r1}<\\{r0}$ \1\&{then}\6
\&{if} $\\{r0}>\\{screen\_depth}$ \1\&{then}\5
$\\{r0}\K\\{r1}$\ \&{else} $\\{r1}\K\\{r0}$;\2\2\6
\&{if} $\\{c0}<0$ \1\&{then}\5
$\\{c0}\K0$;\2\6
\&{if} $\\{c1}>\\{screen\_width}$ \1\&{then}\5
$\\{c1}\K\\{screen\_width}$;\2\6
\&{if} $\\{c1}<\\{c0}$ \1\&{then}\6
\&{if} $\\{c0}>\\{screen\_width}$ \1\&{then}\5
$\\{c0}\K\\{c1}$\ \&{else} $\\{c1}\K\\{c0}$\2\2\par
\U section~482.\fi

\M484. Three sets of coordinates are rampant, and they must be kept straight!
(i)~\MF's main coordinates refer to the edges between pixels. (ii)~\MF's
pixel coordinates (within edge structures) say that the pixel bounded by
$(m,n)$, $(m,n+1)$, $(m+1,n)$, and~$(m+1,n+1)$ is in pixel row number~$n$
and pixel column number~$m$. (iii)~Screen coordinates, on the other hand,
have rows numbered in increasing order from top to bottom, as mentioned
above.

The program here first computes integers $m$ and $n$ such that
pixel column~$m$ of pixel row~$n$ will be at the upper left corner
of the window. Hence pixel column $\|m-\\{c0}$ of pixel row $\|n+\\{r0}$
will be at the upper left corner of the screen.

\Y\P$\4\X484:Compute the offsets between screen coordinates and actual
coordinates\X\S$\6
$\|m\K\\{round\_trunc}(\|x)$;\5
$\|n\K\\{round\_trunc}(\|y)-1$;\6
$\\{m\_window}[\|k]\K\\{c0}-\|m$;\5
$\\{n\_window}[\|k]\K\\{r0}+\|n$\par
\U section~482.\fi

\M485. Now here comes \MF's most complicated operation related to window
display: Given the number~\|k of an open window, the pixels of positive
weight in an edge structure pointed to by~\|h will be shown as \\{black}
in the window; all other pixels will be shown as \\{white}.

\Y\P\4\&{procedure}\1\  \37$\\{disp\_edges}(\|k:\\{window\_number};\,\35\|h:%
\\{pointer})$;\6
\4\&{label} \37$\\{done},\39\\{found}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for list manipulation}\6
\\{already\_there}: \37\\{boolean};\C{is a previous incarnation in the window?}%
\6
\|r: \37\\{integer};\C{row number}\6
\X488:Other local variables for \\{disp\_edges}\X\2\6
\&{begin} \37\&{if} $\\{screen\_OK}$ \1\&{then}\6
\&{if} $\\{left\_col}[\|k]<\\{right\_col}[\|k]$ \1\&{then}\6
\&{if} $\\{top\_row}[\|k]<\\{bot\_row}[\|k]$ \1\&{then}\6
\&{begin} \37$\\{already\_there}\K\\{false}$;\6
\&{if} $\\{last\_window}(\|h)=\|k$ \1\&{then}\6
\&{if} $\\{last\_window\_time}(\|h)=\\{window\_time}[\|k]$ \1\&{then}\5
$\\{already\_there}\K\\{true}$;\2\2\6
\&{if} $\R\\{already\_there}$ \1\&{then}\5
$\\{blank\_rectangle}(\\{left\_col}[\|k],\39\\{right\_col}[\|k],\39\\{top%
\_row}[\|k],\39\\{bot\_row}[\|k])$;\2\6
\X489:Initialize for the display computations\X;\6
$\|p\K\\{link}(\|h)$;\5
$\|r\K\\{n\_window}[\|k]-(\\{n\_min}(\|h)-\\{zero\_field})$;\6
\&{while} $(\|p\I\|h)\W(\|r\G\\{top\_row}[\|k])$ \1\&{do}\6
\&{begin} \37\&{if} $\|r<\\{bot\_row}[\|k]$ \1\&{then}\5
\X486:Display the pixels of edge row \|p in screen row \|r\X;\2\6
$\|p\K\\{link}(\|p)$;\5
$\\{decr}(\|r)$;\6
\&{end};\2\6
\\{update\_screen};\5
$\\{incr}(\\{window\_time}[\|k])$;\5
$\\{last\_window}(\|h)\K\|k$;\5
$\\{last\_window\_time}(\|h)\K\\{window\_time}[\|k]$;\6
\&{end};\2\2\2\6
\&{end};\par
\fi

\M486. Since it takes some work to display a row, we try to avoid recomputation
whenever we can.

\Y\P$\4\X486:Display the pixels of edge row \|p in screen row \|r\X\S$\6
\&{begin} \37\&{if} $\\{unsorted}(\|p)>\\{null1}$ \1\&{then}\5
$\\{sort\_edges}(\|p)$\6
\4\&{else} \&{if} $\\{unsorted}(\|p)=\\{null1}$ \1\&{then}\6
\&{if} $\\{already\_there}$ \1\&{then}\5
\&{goto} \37\\{done};\2\2\2\6
$\\{unsorted}(\|p)\K\\{null1}$;\C{this time we'll paint, but maybe not next
time}\6
\X490:Set up the parameters needed for \\{paint\_row}; but \&{goto} \\{done} if
no painting is needed after all\X;\6
$\\{paint\_row}(\|r,\39\|b,\39\\{row\_transition},\39\|n)$;\6
\4\\{done}: \37\&{end}\par
\U section~485.\fi

\M487. The transition-specification parameter to \\{paint\_row} is always the
same
array.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{row\_transition}: \37\\{trans\_spec};\C{an array of \\{black}/\\{white}
transitions}\par
\fi

\M488. The job remaining is to go through the list $\\{sorted}(\|p)$, unpacking
the
\\{info} fields into \|m and weight, then making \\{black} the pixels whose
accumulated weight~\|w is positive.

\Y\P$\4\X488:Other local variables for \\{disp\_edges}\X\S$\6
\4\|n: \37\\{screen\_col};\C{the highest active index in \\{row\_transition}}\6
\4$\|w,\39\\{ww}$: \37\\{integer};\C{old and new accumulated weight}\6
\4\|b: \37\\{pixel\_color};\C{status of first pixel in the row transitions}\6
\4\|m: \37\\{integer};\C{a screen column less than $\\{right\_col}[\|k]$}\6
\4\|z: \37\\{integer};\C{edge-and-weight without \\{min\_halfword}
compensation}\6
\4\\{m\_adjustment}: \37\\{integer};\C{conversion between edge and screen
coordinates}\6
\4\\{right\_edge}: \37\\{integer};\C{largest edge-and-weight that could affect
the window}\6
\4\\{min\_col}: \37\\{screen\_col};\C{the smallest screen column number in the
window}\par
\U section~485.\fi

\M489. Some precomputed constants make the display calculations faster.

\Y\P$\4\X489:Initialize for the display computations\X\S$\6
$\\{m\_adjustment}\K\\{m\_window}[\|k]-\\{m\_offset}(\|h)$;\6
$\\{right\_edge}\K8\ast(\\{right\_col}[\|k]-1-\\{m\_adjustment})+7$;\6
$\\{min\_col}\K\\{left\_col}[\|k]$\par
\U section~485.\fi

\M490. \P$\X490:Set up the parameters needed for \\{paint\_row}; but \&{goto} %
\\{done} if no painting is needed after all\X\S$\6
$\|n\K0$;\5
$\|w\K0$;\5
$\|q\K\\{sorted}(\|p)$;\5
$\\{row\_transition}[0]\K\\{min\_col}$;\6
\&{while} $\|q>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\|z\K\\{ho}(\\{info}(\|q))$;\6
\&{if} $\|z>\\{right\_edge}$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
$\|m\K(\|z\mathbin{\&{div}}8)+\\{m\_adjustment}$;\C{now \|m is a screen column
$<\\{right\_col}[\|k]$}\6
$\\{ww}\K\|w+(\|z\mathbin{\&{mod}}8)-\\{zero\_w}$;\6
\&{if} $\|w\L0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{ww}>0$ \1\&{then}\6
\&{if} $\|m\G\\{min\_col}$ \1\&{then}\5
\X491:Consider a transition to \\{black} at column \|m\X;\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{ww}\L0$ \1\&{then}\6
\&{if} $\|m\G\\{min\_col}$ \1\&{then}\5
\X492:Consider a transition to \\{white} at column \|m\X;\2\2\2\6
$\|w\K\\{ww}$;\5
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\4\\{found}: \37\X493:Wind up the \\{paint\_row} parameter calculation by
inserting the final transition; \&{goto} \\{done} if no painting is needed\X;%
\par
\U section~486.\fi

\M491. Two consecutive row transitions at the same column cancel each other
out.

\Y\P$\4\X491:Consider a transition to \\{black} at column \|m\X\S$\6
\&{if} $\|m>\\{row\_transition}[\|n]$ \1\&{then}\6
\&{begin} \37\&{if} $\|n=0$ \1\&{then}\5
$\|b\K\\{white}$;\2\6
$\\{incr}(\|n)$;\5
$\\{row\_transition}[\|n]\K\|m$;\6
\&{end}\6
\4\&{else} \&{if} $\|n>0$ \1\&{then}\5
$\\{decr}(\|n)$\2\2\par
\U section~490.\fi

\M492. \P$\X492:Consider a transition to \\{white} at column \|m\X\S$\6
\&{if} $\|m>\\{row\_transition}[\|n]$ \1\&{then}\6
\&{begin} \37\&{if} $\|n=0$ \1\&{then}\5
$\|b\K\\{black}$;\2\6
$\\{incr}(\|n)$;\5
$\\{row\_transition}[\|n]\K\|m$;\6
\&{end}\6
\4\&{else} \&{if} $\|n>0$ \1\&{then}\5
$\\{decr}(\|n)$\2\2\par
\U section~490.\fi

\M493. If the entire row is \\{white} in the window area, we can omit painting
it
when \\{already\_there} is false, since it has already been blanked out in
that case.

When the following code is invoked, $\\{row\_transition}[\|n]$ will be
strictly less than $\\{right\_col}[\|k]$.

\Y\P$\4\X493:Wind up the \\{paint\_row} parameter calculation by inserting the
final transition; \&{goto} \\{done} if no painting is needed\X\S$\6
\&{if} $\|n=0$ \1\&{then}\6
\&{if} $\|w>0$ \1\&{then}\5
$\|b\K\\{black}$\6
\4\&{else} \&{if} $\\{already\_there}$ \1\&{then}\5
$\|b\K\\{white}$\6
\4\&{else} \&{goto} \37\\{done};\2\2\2\6
$\\{incr}(\|n)$;\5
$\\{row\_transition}[\|n]\K\\{right\_col}[\|k]$\par
\U section~490.\fi

\N494.  \[xx] Introduction to the syntactic routines.
Let's pause a moment now and try to look at the Big Picture.
The \MF\ program consists of three main parts: syntactic routines,
semantic routines, and output routines. The chief purpose of the
syntactic routines is to deliver the user's input to the semantic routines,
while parsing expressions and locating operators and operands. The
semantic routines act as an interpreter responding to these operators,
which may be regarded as commands. And the output routines are
periodically called on to produce compact font definitions that can be
used for typesetting or for making interim proof drawings. We have
discussed the basic data structures and many of the details of semantic
operations, so we are good and ready to plunge into the part of \MF\ that
actually controls the activities.

Our current goal is to come to grips with the \\{get\_next} procedure,
which is the keystone of \MF's input mechanism. Each call of \\{get\_next}
sets the value of three variables \\{cur\_cmd}, \\{cur\_mod}, and \\{cur\_sym},
representing the next input token.
$$\vbox{\halign{#\hfil\cr
\hbox{\\{cur\_cmd} denotes a command code from the long list of codes
given earlier;}\cr
\hbox{\\{cur\_mod} denotes a modifier of the command code;}\cr
\hbox{\\{cur\_sym} is the hash address of the symbolic token that was
just scanned,}\cr
\hbox{\qquad or zero in the case of a numeric or string token.}\cr}}$$
Underlying this external behavior of \\{get\_next} is all the machinery
necessary to convert from character files to tokens. At a given time we
may be only partially finished with the reading of several files (for
which \.{input} was specified), and partially finished with the expansion
of some user-defined macros and/or some macro parameters, and partially
finished reading some text that the user has inserted online,
and so on. When reading a character file, the characters must be
converted to tokens; comments and blank spaces must
be removed, numeric and string tokens must be evaluated.

To handle these situations, which might all be present simultaneously,
\MF\ uses various stacks that hold information about the incomplete
activities, and there is a finite state control for each level of the
input mechanism. These stacks record the current state of an implicitly
recursive process, but the \\{get\_next} procedure is not recursive.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_cmd}: \37\\{eight\_bits};\C{current command set by \\{get\_next}}\6
\4\\{cur\_mod}: \37\\{halfword};\C{operand of current command}\6
\4\\{cur\_sym}: \37\\{halfword};\C{hash address of current symbol}\par
\fi

\M495. The \\{print\_cmd\_mod} routine prints a symbolic interpretation of a
command code and its modifier.
It consists of a rather tedious sequence of print
commands, and most of it is essentially an inverse to the \\{primitive}
routine that enters a \MF\ primitive into \\{hash} and \\{eqtb}. Therefore much
of
this procedure appears elsewhere in the program,
together with the corresponding \\{primitive} calls.

\Y\P$\4\X495:Declare the procedure called \\{print\_cmd\_mod}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_cmd\_mod}(\\{cmd}:\\{halfword};\,\35\mathbin{%
\&{mod}}:\\{halfword})$;\2\6
\&{begin} \37\&{case} $\\{cmd}$ \1\&{of}\6
\hbox{\4}\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of primitives%
\X\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ command\ code!]"})$\2\6
\&{endcases};\6
\&{end};\par
\U section~215.\fi

\M496. Here is a procedure that displays a given command in braces, in the
user's transcript file.

\Y\P\4\&{procedure}\1\  \37$\\{show\_cmd\_mod}(\\{cmd},\39\mathbin{\&{mod}})$;%
\2\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\{"})$;\5
$\\{print\_cmd\_mod}(\\{cmd},\39\mathbin{\&{mod}})$;\5
$\\{print\_char}(\.{"\}"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\par
\fi

\N497.  \[xx] Input stacks and states.
The state of \MF's input mechanism appears in the input stack, whose
entries are records with five fields, called \\{index}, \\{start}, \\{loc},
\\{limit}, and \\{name}. The top element of this stack is maintained in a
global variable for which no subscripting needs to be done; the other
elements of the stack appear in an array. Hence the stack is declared thus:

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{in\_state\_record}=$\1\5
\1\&{record} \37\\{index\_field}: \37\\{quarterword};\6
\4$\\{start\_field},\39\\{loc\_field},\39\\{limit\_field},\39\\{name\_field}$: %
\37\\{halfword};\2\6
\&{end};\2\par
\fi

\M498. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{input\_stack}: \37\&{array} $[0\to\\{stack\_size}]$ \1\&{of}\5
\\{in\_state\_record};\2\6
\4\\{input\_ptr}: \37$0\to\\{stack\_size}$;\C{first unused location of \\{input%
\_stack}}\6
\4\\{max\_in\_stack}: \37$0\to\\{stack\_size}$;\C{largest value of \\{input%
\_ptr} when pushing}\6
\4\\{cur\_input}: \37\\{in\_state\_record};\C{the ``top'' input state}\par
\fi

\M499. We've already defined the special variable $\\{loc}\S\\{cur\_input}.%
\\{loc\_field}$
in our discussion of basic input-output routines. The other components of
\\{cur\_input} are defined in the same way:

\Y\P\D \37$\\{index}\S\\{cur\_input}.\\{index\_field}$\C{reference for buffer
information}\par
\P\D \37$\\{start}\S\\{cur\_input}.\\{start\_field}$\C{starting position in %
\\{buffer}}\par
\P\D \37$\\{limit}\S\\{cur\_input}.\\{limit\_field}$\C{end of current line in %
\\{buffer}}\par
\P\D \37$\\{name}\S\\{cur\_input}.\\{name\_field}$\C{name of the current file}%
\par
\fi

\M500. Let's look more closely now at the five control variables
(\\{index},~\\{start},~\\{loc},~\\{limit},~\\{name}),
assuming that \MF\ is reading a line of characters that have been input
from some file or from the user's terminal. There is an array called
\\{buffer} that acts as a stack of all lines of characters that are
currently being read from files, including all lines on subsidiary
levels of the input stack that are not yet completed. We will return to
the other lines when we are finished with the present input file.

(Incidentally, on a machine with byte-oriented addressing, it would be
appropriate to combine \\{buffer} with the \\{str\_pool} array,
letting the buffer entries grow downward from the top of the string pool
and checking that these two tables don't bump into each other.)

The line we are currently working on begins in position \\{start} of the
buffer; the next character we are about to read is $\\{buffer}[\\{loc}]$; and
\\{limit} is the location of the last character present. We always have
$\\{loc}\L\\{limit}$. For convenience, $\\{buffer}[\\{limit}]$ has been set to %
\.{"\%"}, so
that the end of a line is easily sensed.

The \\{name} variable is a string number that designates the name of
the current file, if we are reading a text file. It is zero if we
are reading from the terminal for normal input, or one if we are executing a
\&{readterminal} command.

\fi

\M501. Additional information about the current line is available via the
\\{index} variable, which counts how many lines of characters are present
in the buffer below the current level. We have $\\{index}=0$ when reading
from the terminal and prompting the user for each line; then if the user types,
e.g., `\.{input font}', we will have $\\{index}=1$ while reading
the file \.{font.mf}. However, it does not follow that \\{index} is the
same as the input stack pointer, since many of the levels on the input
stack come from token lists.

The variable \\{in\_open} is equal to the \\{index}
value of the highest non-token-list level. Thus, the number of partially read
lines in the buffer is $\\{in\_open}+1$, and we have $\\{in\_open}=\\{index}$
when we are not reading a token list.

If we are not currently reading from the terminal, or from an input
stream, we are reading from the file variable $\\{input\_file}[\\{index}]$. We
use
the notation \\{terminal\_input} as a convenient abbreviation for $\\{name}=0$,
and \\{cur\_file} as an abbreviation for $\\{input\_file}[\\{index}]$.

The global variable \\{line} contains the line number in the topmost
open file, for use in error messages. If we are not reading from
the terminal, $\\{line\_stack}[\\{index}]$ holds the line number for the
enclosing level, so that \\{line} can be restored when the current
file has been read.

If more information about the input state is needed, it can be
included in small arrays like those shown here. For example,
the current page or segment number in the input file might be
put into a variable \\{page}, maintained for enclosing levels in
`\ignorespaces \\{page\_stack}: \&{array} $[0\to\\{max\_in\_open}]$ \&{of} %
\\{integer}\unskip'
by analogy with \\{line\_stack}.

\Y\P\D \37$\\{terminal\_input}\S(\\{name}=0)$\C{are we reading from the
terminal?}\par
\P\D \37$\\{cur\_file}\S\\{input\_file}[\\{index}]$\C{the current \\{alpha%
\_file} variable}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{in\_open}: \37$0\to\\{max\_in\_open}$;\C{the number of lines in the
buffer, less one}\6
\4\\{input\_file}: \37\&{array} $[1\to\\{max\_in\_open}]$ \1\&{of}\5
\\{alpha\_file};\2\6
\4\\{line}: \37\\{integer};\C{current line number in the current source file}\6
\4\\{line\_stack}: \37\&{array} $[0\to\\{max\_in\_open}]$ \1\&{of}\5
\\{integer};\2\par
\fi

\M502. However, all this discussion about input state really applies only to
the
case that we are inputting from a file. There is another important case,
namely when we are currently getting input from a token list. In this case
$\\{index}>\\{max\_in\_open}$, and the conventions about the other state
variables
are different:

\yskip\hang\\{loc} is a pointer to the current node in the token list, i.e.,
the node that will be read next. If $\\{loc}=\\{null}$, the token list has been
fully read.

\yskip\hang\\{start} points to the first node of the token list; this node
may or may not contain a reference count, depending on the type of token
list involved.

\yskip\hang\\{token\_type}, which takes the place of \\{index} in the
discussion above, is a code number that explains what kind of token list
is being scanned.

\yskip\hang\\{name} points to the \\{eqtb} address of the control sequence
being expanded, if the current token list is a macro not defined by
\&{vardef}. Macros defined by \&{vardef} have $\\{name}=\\{null}$; their name
can be deduced by looking at the first two parameters.

\yskip\hang\\{param\_start}, which takes the place of \\{limit}, tells where
the parameters of the current macro begin in the \\{param\_stack}, if the
current token list is a macro.

\yskip\noindent The \\{token\_type} can take several values, depending on
where the current token list came from:

\yskip\hang\\{parameter}, if a text of suffix parameter is being scanned;

\hang\\{loop\_text}, if the token list being scanned is the body of
a \&{loop};

\hang\\{for\_loop}, if the token list being scanned is the body of
a \&{for} loop;

\hang\\{for\_suffixes\_loop}, if the token list being scanned is the body of
a \&{forsuffixes} loop;

\hang\\{backed\_up}, if the token list being scanned has been inserted as
`to be read again'.

\hang\\{inserted}, if the token list being scanned has been inserted as
part of error recovery;

\hang\\{macro}, if the expansion of a user-defined symbolic token is being
scanned.

\hang\\{identity}, if the expansion of \\{identity\_macro} is being scanned.

\yskip\noindent
The token list begins with a reference count if and only if $\\{token\_type}=%
\\{macro}$.

\Y\P\D \37$\\{token\_type}\S\\{index}$\C{type of current token list}\par
\P\D \37$\\{token\_state}\S(\\{index}>\\{max\_in\_open})$\C{are we scanning a
token list?}\par
\P\D \37$\\{file\_state}\S(\\{index}\L\\{max\_in\_open})$\C{are we scanning a
file line?}\par
\P\D \37$\\{param\_start}\S\\{limit}$\C{base of macro parameters in \\{param%
\_stack}}\par
\P\D \37$\\{parameter}\S\\{max\_in\_open}+1$\C{\\{token\_type} code for
parameter}\par
\P\D \37$\\{loop\_text}\S\\{max\_in\_open}+2$\C{\\{token\_type} code for %
\&{while} texts}\par
\P\D \37$\\{for\_loop}\S\\{max\_in\_open}+3$\C{\\{token\_type} code for \&{for}
texts}\par
\P\D \37$\\{for\_suffixes\_loop}\S\\{max\_in\_open}+4$\C{\\{token\_type} code
for \&{forsuffixes} texts}\par
\P\D \37$\\{backed\_up}\S\\{max\_in\_open}+5$\C{\\{token\_type} code for text
to be reread}\par
\P\D \37$\\{inserted}\S\\{max\_in\_open}+6$\C{\\{token\_type} code for inserted
texts}\par
\P\D \37$\\{macro}\S\\{max\_in\_open}+7$\C{\\{token\_type} code for defined
control sequences}\par
\P\D \37$\\{identity}\S\\{max\_in\_open}+8$\C{\\{token\_type} code for %
\\{identity\_macro}}\par
\fi

\M503. The \\{param\_stack} is an auxiliary array used to hold pointers to the
token
lists for parameters at the current level and subsidiary levels of input.
This stack grows at a different rate from the others.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{param\_stack}: \37\&{array} $[0\to\\{param\_size}]$ \1\&{of}\5
\\{pointer};\C{token list pointers for parameters}\2\6
\4\\{param\_ptr}: \37$0\to\\{param\_size}$;\C{first unused entry in \\{param%
\_stack}}\6
\4\\{max\_param\_stack}: \37\\{integer};\C{largest value of \\{param\_ptr}}\par
\fi

\M504. Thus, the ``current input state'' can be very complicated indeed, since
there
can be many levels and each level can arise in a variety of ways. The
\\{show\_context} procedure, which is used by \MF's error-reporting routine to
print out the current input state on all levels down to the most recent
line of characters from an input file, illustrates most of these conventions.
The global variable \\{base\_ptr} contains the lowest level that was
displayed by this procedure.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{base\_ptr}: \37$0\to\\{stack\_size}$;\C{shallowest level shown by \\{show%
\_context}}\par
\fi

\M505. The status at each level is indicated by printing two lines, where the
first
line indicates what was read so far and the second line shows what remains
to be read. The context is cropped, if necessary, so that the first line
contains at most \\{half\_error\_line} characters, and the second contains
at most \\{error\_line}. Non-current input levels whose \\{token\_type} is
`\\{backed\_up}' are shown only if they have not been fully read.

\Y\P\4\&{procedure}\1\  \37\\{show\_context};\C{prints where the scanner is}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{saved \\{selector}
setting}\6
\X510:Local variables for formatting calculations\X\2\6
\&{begin} \37$\\{base\_ptr}\K\\{input\_ptr}$;\5
$\\{input\_stack}[\\{base\_ptr}]\K\\{cur\_input}$;\C{store current state}\6
\~ \1\&{loop}\ \&{begin} \37$\\{cur\_input}\K\\{input\_stack}[\\{base\_ptr}]$;%
\C{enter into the context}\6
\X506:Display the current context\X;\6
\&{if} $\\{file\_state}$ \1\&{then}\6
\&{if} $(\\{name}>0)\V(\\{base\_ptr}=0)$ \1\&{then}\5
\&{goto} \37\\{done};\2\2\6
$\\{decr}(\\{base\_ptr})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{cur\_input}\K\\{input\_stack}[\\{input\_ptr}]$;\C{restore
original state}\6
\&{end};\par
\fi

\M506. \P$\X506:Display the current context\X\S$\6
\&{if} $(\\{base\_ptr}=\\{input\_ptr})\V\\{file\_state}\V(\\{token\_type}\I%
\\{backed\_up})\V(\\{loc}\I\\{null})$ \1\&{then}\C{we omit backed-up token
lists that have already been read}\6
\&{begin} \37$\\{tally}\K0$;\C{get ready to count characters}\6
$\\{old\_setting}\K\\{selector}$;\6
\&{if} $\\{file\_state}$ \1\&{then}\6
\&{begin} \37\X507:Print location of current line\X;\6
\X513:Pseudoprint the line\X;\6
\&{end}\6
\4\&{else} \&{begin} \37\X508:Print type of token list\X;\6
\X514:Pseudoprint the token list\X;\6
\&{end};\2\6
$\\{selector}\K\\{old\_setting}$;\C{stop pseudoprinting}\6
\X512:Print two lines using the tricky pseudoprinted information\X;\6
\&{end}\2\par
\U section~505.\fi

\M507. This routine should be changed, if necessary, to give the best possible
indication of where the current line resides in the input file.
For example, on some systems it is best to print both a page and line number.

\Y\P$\4\X507:Print location of current line\X\S$\6
\&{if} $\\{terminal\_input}$ \1\&{then}\6
\&{if} $\\{base\_ptr}=0$ \1\&{then}\5
$\\{print\_nl}(\.{"<*>"})$\6
\4\&{else} $\\{print\_nl}(\.{"<insert>\ "})$\2\6
\4\&{else} \&{begin} \37$\\{print\_nl}(\.{"l."})$;\5
$\\{print\_int}(\\{line})$;\6
\&{end};\2\6
$\\{print\_char}(\.{"\ "})$\par
\U section~506.\fi

\M508. \P$\X508:Print type of token list\X\S$\6
\&{case} $\\{token\_type}$ \1\&{of}\6
\4\\{parameter}: \37$\\{print\_nl}(\.{"<argument>\ "})$;\6
\4\\{backed\_up}: \37\&{if} $\\{loc}=\\{null}$ \1\&{then}\5
$\\{print\_nl}(\.{"<recently\ read>\ "})$\6
\4\&{else} $\\{print\_nl}(\.{"<to\ be\ read\ again>\ "})$;\2\6
\4\\{inserted}: \37$\\{print\_nl}(\.{"<inserted\ text>\ "})$;\6
\4\\{while\_loop}: \37$\\{print\_nl}(\.{"<while...do>\ "})$;\6
\4\\{for\_loop}: \37$\\{print\_nl}(\.{"<for...do>\ "})$;\6
\4\\{for\_suffixes\_loop}: \37$\\{print\_nl}(\.{"<forsuffixes...do>\ "})$;\6
\4\\{macro}: \37\&{begin} \37\\{print\_ln};\6
\&{if} $\\{name}\I\\{null}$ \1\&{then}\5
$\\{print}(\\{text}(\\{name}))$\6
\4\&{else} \X509:Print the name of a \&{vardef}'d macro\X;\2\6
\&{end};\6
\4\\{identity}: \37$\\{print\_nl}(\.{"<scanned\ expression>\ "})$;\6
\4\&{othercases} \37$\\{print\_nl}(\.{"?"})$\C{this should never happen}\2\6
\&{endcases}\par
\U section~506.\fi

\M509. The first two parameters of a macro defined by \&{vardef} will be token
lists representing the macro's prefix and ``at point.'' By putting these
together, we get the macro's full name.

\Y\P$\4\X509:Print the name of a \&{vardef}'d macro\X\S$\6
\&{begin} \37$\|p\K\\{param\_stack}[\\{param\_start}]$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\5
$\\{show\_token\_list}(\\{param\_stack}[\\{param\_start}+1],\39\\{null},%
\391000)$\6
\4\&{else} \&{begin} \37$\|q\K\|p$;\6
\&{while} $\\{link}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{link}(\|q)\K\\{param\_stack}[\\{param\_start}+1]$;\5
$\\{show\_token\_list}(\|p,\39\\{null},\391000)$;\5
$\\{link}(\|q)\K\\{null}$;\6
\&{end};\2\6
\&{end}\par
\U section~508.\fi

\M510. Now it is necessary to explain a little trick. We don't want to store a
long
string that corresponds to a token list, because that string might take up
lots of memory; and we are printing during a time when an error message is
being given, so we dare not do anything that might overflow one of \MF's
tables. So `pseudoprinting' is the answer: We enter a mode of printing
that stores characters into a buffer of length \\{error\_line}, where character
$k+1$ is placed into \hbox{$\\{trick\_buf}[\|k\mathbin{\&{mod}}\\{error%
\_line}]$} if
$\|k<\\{trick\_count}$, otherwise character \|k is dropped. Initially we set
$\\{tally}\K0$ and $\\{trick\_count}\K1000000$; then when we reach the
point where transition from line 1 to line 2 should occur, we
set $\\{first\_count}\K\\{tally}$ and $\\{trick\_count}\K\hbox{max}(\\{error%
\_line},\\{tally}+1+\\{error\_line}-\\{half\_error\_line})$. At the end of the
pseudoprinting, the values of \\{first\_count}, \\{tally}, and
\\{trick\_count} give us all the information we need to print the two lines,
and all of the necessary text is in \\{trick\_buf}.

Namely, let \|l be the length of the descriptive information that appears
on the first line. The length of the context information gathered for that
line is $\|k=\\{first\_count}$, and the length of the context information
gathered for line~2 is $m=\min(\\{tally}, \\{trick\_count})-k$. If $\|l+\|k\L%
\|h$,
where $\|h=\\{half\_error\_line}$, we print $\\{trick\_buf}[0\to\|k-1]$ after
the
descriptive information on line~1, and set $\|n\K\|l+\|k$; here \|n is the
length of line~1. If $l+k>h$, some cropping is necessary, so we set $\|n\K\|h$
and print `\.{...}' followed by
$$\hbox{$\\{trick\_buf}[(\|l+\|k-\|h+3)\to\|k-1]$,}$$
where subscripts of \\{trick\_buf} are circular modulo \\{error\_line}. The
second line consists of \|n~spaces followed by $\\{trick\_buf}[\|k\to(\|k+%
\|m-1)]$,
unless $\|n+\|m>\\{error\_line}$; in the latter case, further cropping is done.
This is easier to program than to explain.

\Y\P$\4\X510:Local variables for formatting calculations\X\S$\6
\4\|i: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\6
\4\|j: \37$0\to\\{buf\_size}$;\C{end of current line in \\{buffer}}\6
\4\|l: \37$0\to\\{half\_error\_line}$;\C{length of descriptive information on
line 1}\6
\4\|m: \37\\{integer};\C{context information gathered for line 2}\6
\4\|n: \37$0\to\\{error\_line}$;\C{length of line 1}\6
\4\|p: \37\\{integer};\C{starting or ending place in \\{trick\_buf}}\6
\4\|q: \37\\{integer};\C{temporary index}\par
\U section~505.\fi

\M511. The following code sets up the print routines so that they will gather
the desired information.

\Y\P\D \37$\\{begin\_pseudoprint}\S$\1\6
\&{begin} \37$\|l\K\\{tally}$;\5
$\\{tally}\K0$;\5
$\\{selector}\K\\{pseudo}$;\5
$\\{trick\_count}\K1000000$;\6
\&{end}\2\par
\P\D \37$\\{set\_trick\_count}\S$\1\6
\&{begin} \37$\\{first\_count}\K\\{tally}$;\5
$\\{trick\_count}\K\\{tally}+1+\\{error\_line}-\\{half\_error\_line}$;\6
\&{if} $\\{trick\_count}<\\{error\_line}$ \1\&{then}\5
$\\{trick\_count}\K\\{error\_line}$;\2\6
\&{end}\2\par
\fi

\M512. And the following code uses the information after it has been gathered.

\Y\P$\4\X512:Print two lines using the tricky pseudoprinted information\X\S$\6
\&{if} $\\{trick\_count}=1000000$ \1\&{then}\5
\\{set\_trick\_count};\C{\\{set\_trick\_count} must be performed}\2\6
\&{if} $\\{tally}<\\{trick\_count}$ \1\&{then}\5
$\|m\K\\{tally}-\\{first\_count}$\6
\4\&{else} $\|m\K\\{trick\_count}-\\{first\_count}$;\C{context on line 2}\2\6
\&{if} $\|l+\\{first\_count}\L\\{half\_error\_line}$ \1\&{then}\6
\&{begin} \37$\|p\K0$;\5
$\|n\K\|l+\\{first\_count}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print}(\.{"..."})$;\5
$\|p\K\|l+\\{first\_count}-\\{half\_error\_line}+3$;\5
$\|n\K\\{half\_error\_line}$;\6
\&{end};\2\6
\&{for} $\|q\K\|p\mathrel{\&{to}}\\{first\_count}-1$ \1\&{do}\5
$\\{print\_char}(\\{trick\_buf}[\|q\mathbin{\&{mod}}\\{error\_line}])$;\2\6
\\{print\_ln};\6
\&{for} $\|q\K1\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{print\_char}(\.{"\ "})$;\C{print \|n spaces to begin line~2}\2\6
\&{if} $\|m+\|n\L\\{error\_line}$ \1\&{then}\5
$\|p\K\\{first\_count}+\|m$\6
\4\&{else} $\|p\K\\{first\_count}+(\\{error\_line}-\|n-3)$;\2\6
\&{for} $\|q\K\\{first\_count}\mathrel{\&{to}}\|p-1$ \1\&{do}\5
$\\{print\_char}(\\{trick\_buf}[\|q\mathbin{\&{mod}}\\{error\_line}])$;\2\6
\&{if} $\|m+\|n>\\{error\_line}$ \1\&{then}\5
$\\{print}(\.{"..."})$\2\par
\U section~506.\fi

\M513. But the trick is distracting us from our current goal, which is to
understand the input state. So let's concentrate on the data structures that
are being pseudoprinted as we finish up the \\{show\_context} procedure.

\Y\P$\4\X513:Pseudoprint the line\X\S$\6
\\{begin\_pseudoprint};\6
\&{if} $\\{limit}>0$ \1\&{then}\6
\&{for} $\|i\K\\{start}\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\6
\&{begin} \37\&{if} $\|i=\\{loc}$ \1\&{then}\5
\\{set\_trick\_count};\2\6
$\\{print}(\\{buffer}[\|i])$;\6
\&{end}\2\2\par
\U section~506.\fi

\M514. \P$\X514:Pseudoprint the token list\X\S$\6
\\{begin\_pseudoprint};\6
\&{if} $\\{token\_type}\I\\{macro}$ \1\&{then}\5
$\\{show\_token\_list}(\\{start},\39\\{loc},\39100000)$\6
\4\&{else} $\\{show\_token\_list}(\\{link}(\\{start}),\39\\{loc},\39100000)$%
\C{avoid reference count}\2\par
\U section~506.\fi

\M515. Here is the missing piece of \\{show\_token\_list} that is activated
when the
token beginning line~2 is about to be shown:

\Y\P$\4\X515:Do magic computation\X\S$\6
\\{set\_trick\_count}\par
\U section~205.\fi

\N516.  \[xx] Maintaining the input stacks.
The following subroutines change the input status in commonly needed ways.

First comes \\{push\_input}, which stores the current state and creates a
new level (having, initially, the same properties as the old).

\Y\P\D \37$\\{push\_input}\S\hbox{}$\C{enter a new input level, save the old}\6
\&{begin} \37\&{if} $\\{input\_ptr}>\\{max\_in\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_in\_stack}\K\\{input\_ptr}$;\6
\&{if} $\\{input\_ptr}=\\{stack\_size}$ \1\&{then}\5
$\\{overflow}(\.{"input\ stack\ size"},\39\\{stack\_size})$;\2\6
\&{end};\2\6
$\\{input\_stack}[\\{input\_ptr}]\K\\{cur\_input}$;\C{stack the record}\6
$\\{incr}(\\{input\_ptr})$;\6
\&{end}\par
\fi

\M517. And of course what goes up must come down.

\Y\P\D \37$\\{pop\_input}\S\hbox{}$\C{leave an input level, re-enter the old}\6
\&{begin} \37$\\{decr}(\\{input\_ptr})$;\5
$\\{cur\_input}\K\\{input\_stack}[\\{input\_ptr}]$;\6
\&{end}\par
\fi

\M518. Here is a procedure that starts a new level of token-list input, given
a token list \|p and its type \|t. If $\|t=\\{macro}$, the calling routine
should
set \\{name} and \\{loc}.

\Y\P\D \37$\\{back\_list}(\#)\S\\{begin\_token\_list}(\#,\39\\{backed\_up})$%
\C{backs up a simple token list}\par
\P\D \37$\\{ins\_list}(\#)\S\\{begin\_token\_list}(\#,\39\\{inserted})$%
\C{inserts a simple token list}\par
\Y\P\4\&{procedure}\1\  \37$\\{begin\_token\_list}(\|p:\\{pointer};\,\35\|t:%
\\{quarterword})$;\2\6
\&{begin} \37\\{push\_input};\5
$\\{start}\K\|p$;\5
$\\{token\_type}\K\|t$;\6
\&{if} $\|t=\\{macro}$ \1\&{then}\C{the token list starts with a reference
count}\6
\&{begin} \37$\\{add\_token\_ref}(\|p)$;\5
$\\{param\_start}\K\\{param\_ptr}$;\6
\&{end}\6
\4\&{else} $\\{loc}\K\|p$;\2\6
\&{end};\par
\fi

\M519. When a token list has been fully scanned, the following computations
should be done as we leave that level of input.

\Y\P\4\&{procedure}\1\  \37\\{end\_token\_list};\C{leave a token-list input
level}\6
\4\&{var} \37\|p: \37\\{pointer};\C{temporary register}\2\6
\&{begin} \37\&{if} $\\{token\_type}\G\\{backed\_up}$ \1\&{then}\C{token list
to be deleted}\6
\&{begin} \37\&{if} $\\{token\_type}\L\\{inserted}$ \1\&{then}\5
$\\{flush\_list}(\\{start})$\6
\4\&{else} \&{begin} \37$\\{delete\_token\_ref}(\\{start})$;\C{update reference
count}\6
\&{while} $\\{param\_ptr}>\\{param\_start}$ \1\&{do}\C{parameters must be
flushed}\6
\&{begin} \37$\\{decr}(\\{param\_ptr})$;\5
$\|p\K\\{param\_stack}[\\{param\_ptr}]$;\6
\&{if} $\\{link}(\|p)=\\{null1}$ \1\&{then}\C{it's an \&{expr} parameter}\6
\&{begin} \37$\\{recycle\_value}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{value\_node\_size})$;\6
\&{end}\6
\4\&{else} $\\{flush\_list}(\|p)$;\C{it's a \&{suffix} or \&{text} parameter}\2%
\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\\{pop\_input};\5
\\{check\_interrupt};\6
\&{end};\par
\fi

\M520. The contents of $\\{cur\_cmd},\\{cur\_mod},\\{cur\_sym}$ are placed into
an equivalent
token by the \\{cur\_tok} routine.

\Y\P\4\&{function}\1\  \37\\{cur\_tok}: \37\\{pointer};\2\6
\&{begin} \37\&{if} $\\{cur\_sym}=0$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|p)\K\\{cur\_mod}$;\5
$\\{info}(\|p)\K\\{cur\_cmd}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cur\_sym}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M521. Sometimes \MF\ has read too far and wants to ``unscan'' what it has
seen. The \\{back\_input} procedure takes care of this by putting the token
just scanned back into the input stream, ready to be read again.
If $\\{cur\_sym}\I0$, the values of \\{cur\_cmd} and \\{cur\_mod} are
irrelevant.

\Y\P\4\&{procedure}\1\  \37\\{back\_input};\C{undoes one token of input}\6
\4\&{var} \37\|p: \37\\{pointer};\C{a token list of length one}\2\6
\&{begin} \37\&{while} $\\{token\_state}\W(\\{loc}=\\{null})$ \1\&{do}\5
\\{end\_token\_list};\C{conserve stack space}\2\6
$\|p\K\\{cur\_tok}$;\5
$\\{back\_list}(\|p)$;\6
\&{end};\par
\fi

\M522. The \\{back\_error} routine is used when we want to restore or replace
an
offending token just before issuing an error message.  We disable interrupts
during the call of \\{back\_input} so that the help message won't be lost.

\Y\P\4\&{procedure}\1\  \37\\{back\_error};\C{back up one token and call %
\\{error}}\2\6
\&{begin} \37$\\{OK\_to\_interrupt}\K\\{false}$;\5
\\{back\_input};\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
\\{error};\6
\&{end};\7
\4\&{procedure}\1\  \37\\{ins\_error};\C{back up one inserted token and call %
\\{error}}\2\6
\&{begin} \37$\\{OK\_to\_interrupt}\K\\{false}$;\5
\\{back\_input};\5
$\\{token\_type}\K\\{inserted}$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
\\{error};\6
\&{end};\par
\fi

\M523. The \\{begin\_file\_reading} procedure starts a new level of input for
lines
of characters to be read from a file, or as an insertion from the
terminal. It does not take care of opening the file, nor does it set \\{loc}
or \\{limit} or \\{line}.

\Y\P\4\&{procedure}\1\  \37\\{begin\_file\_reading};\2\6
\&{begin} \37\&{if} $\\{in\_open}=\\{max\_in\_open}$ \1\&{then}\5
$\\{overflow}(\.{"text\ input\ levels"},\39\\{max\_in\_open})$;\2\6
\&{if} $\\{first}=\\{buf\_size}$ \1\&{then}\5
$\\{overflow}(\.{"buffer\ size"},\39\\{buf\_size})$;\2\6
$\\{incr}(\\{in\_open})$;\5
\\{push\_input};\5
$\\{index}\K\\{in\_open}$;\5
$\\{line\_stack}[\\{index}]\K\\{line}$;\5
$\\{start}\K\\{first}$;\5
$\\{state}\K\\{mid\_line}$;\5
$\\{name}\K0$;\C{\\{terminal\_input} is now \\{true}}\6
\&{end};\par
\fi

\M524. Conversely, the variables must be downdated when such a level of input
is finished:

\Y\P\4\&{procedure}\1\  \37\\{end\_file\_reading};\2\6
\&{begin} \37$\\{first}\K\\{start}$;\5
$\\{line}\K\\{line\_stack}[\\{index}]$;\6
\&{if} $\\{name}>1$ \1\&{then}\5
$\\{a\_close}(\\{cur\_file})$;\C{forget it}\2\6
\\{pop\_input};\5
$\\{decr}(\\{in\_open})$;\6
\&{end};\par
\fi

\M525. In order to keep the stack from overflowing during a long sequence of
inserted `\.{show}' commands, the following routine removes completed
error-inserted lines from memory.

\Y\P\4\&{procedure}\1\  \37\\{clear\_for\_error\_prompt};\2\6
\&{begin} \37\&{while} $\\{file\_state}\W\\{terminal\_input}\W\30(\\{input%
\_ptr}>0)\W(\\{loc}=\\{limit})$ \1\&{do}\5
\\{end\_file\_reading};\2\6
\\{print\_ln};\5
\\{clear\_terminal};\6
\&{end};\par
\fi

\M526. To get \MF's whole input mechanism going, we perform the following
actions.

\Y\P$\4\X526:Initialize the input routines\X\S$\6
\&{begin} \37$\\{input\_ptr}\K0$;\5
$\\{max\_in\_stack}\K0$;\5
$\\{in\_open}\K0$;\5
$\\{max\_buf\_stack}\K0$;\5
$\\{param\_ptr}\K0$;\5
$\\{max\_param\_stack}\K0$;\5
$\\{scanner\_status}\K\\{normal}$;\5
$\\{first}\K1$;\5
$\\{start}\K1$;\5
$\\{index}\K0$;\5
$\\{line}\K0$;\5
$\\{name}\K0$;\5
$\\{force\_eof}\K\\{false}$;\6
\&{if} $\R\\{init\_terminal}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
$\\{limit}\K\\{last}$;\5
$\\{first}\K\\{last}+1$;\C{\\{init\_terminal} has set \\{loc} and \\{last}}\6
\&{end}\par
\U section~816.\fi

\N527.  \[xx] Getting the next token.
The heart of \MF's input mechanism is the \\{get\_next} procedure, which
we shall develop in the next few paragraphs. Perhaps we shouldn't actually
call it the ``heart,'' however; it really acts as \MF's eyes and
mouth, reading the source files and gobbling them up. And it also helps
\MF\ to regurgitate stored token lists that are to be processed again.

The main duty of \\{get\_next} is to input one token and to set \\{cur\_cmd}
and \\{cur\_mod} to that token's command code and modifier. Furthermore, if
the input token is a symbolic token, that token's \\{hash} address
is stored in \\{cur\_sym}; otherwise \\{cur\_sym} is set to zero.

Underlying this simple description is a certain amount of complexity
because of all the cases that need to be handled, as explained above.
However, the inner loop of \\{get\_next} is reasonably short and fast.

When \\{get\_next} is asked to get the next token of a \&{readterminal} line,
it sets $\\{cur\_cmd}=\\{end\_read\_terminal}$ and $\\{cur\_mod}=\\{cur%
\_sym}=0$ in the case
that no more tokens appear on that line. The \\{end\_read\_terminal} command
cannot arise in any other way.

\fi

\M528. Before getting into \\{get\_next}, let's consider the subroutine that
is called when an `\&{outer}' symbolic token has been scanned or
when the end of a file has been reached. These two cases are distinguished
by \\{cur\_sym}, which is zero at the end of a file.

\Y\P\4\&{procedure}\1\  \37\\{check\_outer\_validity};\6
\4\&{var} \37\|p: \37\\{pointer};\C{points to inserted token list}\6
\|q: \37\\{pointer};\C{auxiliary pointer}\2\6
\&{begin} \37\&{if} $\\{scanner\_status}\I\\{normal}$ \1\&{then}\6
\&{begin} \37\X529:Back up an outer symbolic token so that it can be reread\X;\6
\&{if} $\\{scanner\_status}>\\{skipping}$ \1\&{then}\5
\X530:Tell the user what has run away and try to recover\X\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Incomplete\ if"})$;\5
$\\{print}(\.{";\ all\ text\ was\ ignored\ after\ line\ "})$;\5
$\\{print\_int}(\\{skip\_line})$;\5
$\\{help3}(\.{"A\ forbidden\ \`outer\'\ token\ occurred\ in\ skipped\ text."})$%
\6
$(\.{"This\ kind\ of\ error\ happens\ when\ you\ say\ \`if...\'\ and\
forget"})$\6
$(\.{"the\ matching\ \`fi\'.\ I\'ve\ inserted\ a\ \`fi\';\ this\ might\
work."})$;\6
\&{if} $\\{cur\_sym}=0$ \1\&{then}\5
$\\{help\_line}[2]\K\30\.{"The\ file\ ended\ while\ I\ was\ skipping\
conditional\ text."}$;\2\6
$\\{cur\_sym}\K\\{frozen\_fi}$;\5
\\{ins\_error};\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\M529. \P$\X529:Back up an outer symbolic token so that it can be reread\X\S$\6
\&{if} $\\{cur\_sym}\I0$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cur\_sym}$;\5
$\\{back\_list}(\|p)$;\C{prepare to read the symbolic token again}\6
$\\{cur\_cmd}\K\\{relax}$;\5
$\\{cur\_sym}\K\\{frozen\_relax}$;\C{replace it by relaxation}\6
\&{end}\2\par
\U section~528.\fi

\M530. \P$\X530:Tell the user what has run away and try to recover\X\S$\6
\&{begin} \37\\{runaway};\C{print the definition-so-far}\6
\&{if} $\\{cur\_sym}=0$ \1\&{then}\5
$\\{print\_err}(\.{"File\ ended"})$\6
\4\&{else} \&{begin} \37$\\{cur\_sym}\K0$;\5
$\\{print\_err}(\.{"Forbidden\ token\ found"})$;\6
\&{end};\2\6
$\\{print}(\.{"\ while\ scanning\ definition\ of\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{frozen\_end\_def}$;\5
$\\{ins\_list}(\|p)$;\5
$\\{help4}(\.{"I\ suspect\ you\ have\ forgotten\ an\ \`enddef\',\ causing\
me"})$\6
$(\.{"to\ read\ past\ where\ you\ wanted\ me\ to\ stop."})$\6
$(\.{"I\'ll\ try\ to\ recover;\ but\ if\ the\ error\ is\ serious,"})$\6
$(\.{"you\'d\ better\ type\ \`E\'\ or\ \`X\'\ now\ and\ fix\ your\ file."})$;\6
$\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\6
\&{end}\par
\U section~528.\fi

\M531. \P$\X531:Declare the procedure called \\{runaway}\X\S$\6
\\{FIXTHIS}\par
\U section~155.\fi

\M532. We need to mention a procedure that may be called by \\{get\_next}.

\Y\P\4\&{procedure}\1\  \37\\{firm\_up\_the\_line};\5
\\{forward};\par
\fi

\M533. And now we're ready to take the plunge into \\{get\_next} itself.

\Y\P\D \37$\\{switch}=25$\C{a label in \\{get\_next}}\par
\P\D \37$\\{start\_numeric\_token}=85$\C{another}\par
\P\D \37$\\{start\_decimal\_token}=86$\C{and another}\par
\P\D \37$\\{fin\_numeric\_token}=87$\C{and still another, although \&{goto}  is
considered harmful}\par
\Y\P\4\&{procedure}\1\  \37\\{get\_next};\C{sets \\{cur\_cmd}, \\{cur\_mod}, %
\\{cur\_sym} to next token}\6
\4\&{label} \37$\\{restart},\39$\C{go here to get the next input token}\6
$\\{exit},\39$\C{go here when the next input token has been got}\6
$\\{found},\39$\C{go here when the end of a symbolic token has been found}\6
$\\{start\_numeric\_token},\39\\{start\_decimal\_token},\39\\{fin\_numeric%
\_token}$;\C{go here at crucial stages when scanning a number}\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{an index into \\{buffer}}\2\6
\&{begin} \37\\{restart}: \37$\\{cur\_sym}\K0$;\6
\&{if} $\\{file\_state}$ \1\&{then}\5
\X535:Input from external file; \&{goto} \\{restart} if no input found, or %
\&{return} if a non-symbolic token is found\X\6
\4\&{else} \X541:Input from token list; \&{goto} \\{restart} if end of list or
if a parameter needs to be expanded, or \&{return} if a non-symbolic token is
found\X;\2\6
\X534:Finish getting the symbolic token in \\{cur\_sym}\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M534. \P$\X534:Finish getting the symbolic token in \\{cur\_sym}\X\S$\6
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_sym})$;\5
$\\{cur\_mod}\K\\{equiv}(\\{cur\_sym})$;\6
\&{if} $\\{cur\_cmd}\G\\{outer\_tag}$ \1\&{then}\6
\&{begin} \37\\{check\_outer\_validity};\6
\&{if} $\\{cur\_cmd}\G\\{outer\_tag}$ \1\&{then}\5
$\\{cur\_cmd}\K\\{cur\_cmd}-\\{outer\_tag}$;\2\6
\&{end}\2\par
\U section~533.\fi

\M535. A percent sign appears in $\\{buffer}[\\{limit}]$; this makes it
unnecessary
to have a special test for end-of-line.

\Y\P$\4\X535:Input from external file; \&{goto} \\{restart} if no input found,
or \&{return} if a non-symbolic token is found\X\S$\6
\&{begin} \37\\{switch}: \37$\|c\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\5
$\\{class}\K\\{char\_class}[\|c]$;\6
\&{case} $\\{class}$ \1\&{of}\6
\4\\{digit\_class}: \37\&{goto} \37\\{start\_numeric\_token};\6
\4\\{period\_class}: \37\&{begin} \37$\\{class}\K\\{char\_class}[\\{buffer}[%
\\{loc}]]$;\6
\&{if} $\\{class}>\\{period\_class}$ \1\&{then}\5
\&{goto} \37\\{switch}\6
\4\&{else} \&{if} $\\{class}=\\{period\_class}$ \1\&{then}\6
\&{begin} \37$\|n\K0$;\5
\&{goto} \37\\{start\_decimal\_token};\6
\&{end};\2\2\6
\4\\{space\_class}: \37\&{goto} \37\\{switch};\6
\4\\{percent\_class}: \37\&{begin} \37\X544:Move to next line of file, or %
\&{goto} \\{restart} if there is no next line, or \&{return} if a %
\&{readterminal} line has finished\X;\6
\\{check\_interrupt};\5
\&{goto} \37\\{switch};\6
\&{end};\6
\4\\{string\_class}: \37\X536:Get a string token and \&{return}\X;\6
\4\\{isolated\_classes}: \37\&{begin} \37$\|k\K\\{loc}-1$;\5
\&{goto} \37\\{found};\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\C{letters, etc.}\6
\&{endcases};\6
$\|k\K\\{loc}-1$;\6
\&{while} $\\{char\_class}[\\{buffer}[\\{loc}]]=\\{class}$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{goto} \37\\{found};\6
\4\\{start\_numeric\_token}: \37\X538:Get the integer part \|n of a numeric
token; set $\|f\K0$ and \&{goto} \\{fin\_numeric\_token} if there is no decimal
point\X;\6
\4\\{start\_decimal\_token}: \37\X539:Get the fraction part \|f of a numeric
token\X;\6
\4\\{fin\_numeric\_token}: \37\X540:Pack the numeric and fraction parts of a
numeric token and \&{return}\X;\6
\4\\{found}: \37$\\{cur\_sym}\K\\{id\_lookup}(\|k,\39\\{loc}-\|k)$;\2\6
\&{end}\par
\U section~533.\fi

\M536. \P$\X536:Get a string token and \&{return}\X\S$\6
\&{begin} \37\&{if} $\\{buffer}[\\{loc}]=\.{""}\.{""}$ \1\&{then}\5
$\\{cur\_mod}=\.{""}$\6
\4\&{else} \&{begin} \37$\|k\K\\{loc}$;\5
$\\{buffer}[\\{limit}+1]\K\.{""}\.{""}$;\6
\1\&{repeat} \37$\\{incr}(\\{loc})$;\6
\4\&{until}\5
$\\{buffer}[\\{loc}]=\.{""}\.{""}$;\2\6
\&{if} $\\{loc}>\\{limit}$ \1\&{then}\5
\X537:Decry the missing string delimiter and \&{goto} \\{restart}\X;\2\6
\&{if} $\\{loc}=\|k+1$ \1\&{then}\5
$\\{cur\_mod}\K\\{buffer}[\|k]$\6
\4\&{else} \&{begin} \37$\\{str\_room}(\\{loc}-\|k)$;\6
\1\&{repeat} \37$\\{append\_char}(\\{buffer}[\|k])$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|k=\\{loc}$;\2\6
$\\{cur\_mod}\K\\{make\_string}$;\6
\&{end};\2\6
\&{end};\2\6
$\\{incr}(\\{loc})$;\5
$\\{cur\_cmd}\K\\{string\_token}$;\5
\&{return};\6
\&{end}\par
\U section~535.\fi

\M537. We go to \\{restart} after this error message, instead of to \\{switch},
because the \\{clear\_for\_error\_prompt} routine might have reinstated
\\{token\_state} after \\{error} has finished.

\Y\P$\4\X537:Decry the missing string delimiter and \&{goto} \\{restart}\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Incomplete\ string\ constant\ has\ been\
flushed"})$;\5
$\\{help3}(\.{"Strings\ should\ finish\ on\ the\ same\ line\ as\ they\
began."})$\6
$(\.{"I\'ve\ deleted\ the\ partial\ string;\ you\ might\ want\ to"})$\6
$(\.{"insert\ another\ by\ typing,\ e.g.,\ \`I"}\.{"new\ string"}\.{"\'."})%
\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~536.\fi

\M538. \P$\X538:Get the integer part \|n of a numeric token; set $\|f\K0$ and %
\&{goto} \\{fin\_numeric\_token} if there is no decimal point\X\S$\6
$\|n=\|c-\.{"0"}$;\6
\&{while} $\\{char\_class}[\\{buffer}[\\{loc}]]=\\{digit\_class}$ \1\&{do}\6
\&{begin} \37\&{if} $\|n<4096$ \1\&{then}\5
$\|n\K10\ast\|n+\\{buffer}[\\{loc}]-\.{"0"}$;\2\6
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\&{if} $(\\{buffer}[\\{loc}]\I\.{"."})\V(\\{char\_class}[\\{buffer}[\\{loc}+1]]%
\I\\{digit\_class})$ \1\&{do}\6
\&{begin} \37$\|f\K0$;\5
\&{goto} \37\\{fin\_numeric\_token};\6
\&{end}\6
\4\&{else} $\\{incr}(\\{loc})$\2\par
\U section~535.\fi

\M539. \P$\X539:Get the fraction part \|f of a numeric token\X\S$\6
$\|k\K0$;\6
\1\&{repeat} \37\&{if} $\|k<17$ \1\&{then}\C{digits for $\|k\G17$ cannot affect
the result}\6
\&{begin} \37$\\{dig}[\|k]\K\\{buffer}[\\{loc}]-\.{"0"}$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{incr}(\\{loc})$;\6
\4\&{until}\5
$\\{char\_class}[\\{buffer}[\\{loc}]]\I\\{digit\_class}$;\2\6
$\|f\K\\{round\_decimals}(\|k)$\par
\U section~535.\fi

\M540. \P$\X540:Pack the numeric and fraction parts of a numeric token and %
\&{return}\X\S$\6
\&{if} $\|n<4096$ \1\&{then}\5
$\\{cur\_mode}\K\|n\ast\\{unity}+\|f$\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Enormous\ number\ has\ been\
reduced"})$;\5
$\\{help2}(\.{"I\ can\'t\ handle\ numbers\ bigger\ than\ about\ 4095.99998;"})$%
\6
$(\.{"so\ I\'ve\ changed\ your\ constant\ to\ that\ maximum\ amount."})$;\5
$\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\5
$\\{cur\_mod}\K\O{1777777777}$;\6
\&{end};\2\6
$\\{cur\_cmd}\K\\{numeric\_token}$;\5
\&{return}\par
\U section~535.\fi

\M541. Let's consider now what happens when \\{get\_next} is looking at a token
list.

\Y\P$\4\X541:Input from token list; \&{goto} \\{restart} if end of list or if a
parameter needs to be expanded, or \&{return} if a non-symbolic token is found%
\X\S$\6
\&{if} $\\{loc}>\\{hi\_mem\_base}$ \1\&{then}\C{one-word token}\6
\&{begin} \37$\\{cur\_sym}\K\\{info}(\\{loc})$;\5
$\\{loc}\K\\{link}(\\{loc})$;\C{move to next}\6
\&{if} $\\{cur\_sym}\G\\{expr\_base}$ \1\&{then}\6
\&{if} $\\{cur\_sym}\G\\{suffix\_base}$ \1\&{then}\5
\X542:Insert a suffix or text parameter and \&{goto} \\{restart}\X\6
\4\&{else} \&{begin} \37$\\{cur\_cmd}\K\\{expr\_param}$;\5
$\\{cur\_mod}\K\\{param\_stack}[\\{param\_start}+\\{cur\_sym}-(\\{expr%
\_base}+1)]$;\5
\&{return};\6
\&{end};\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{loc}>\\{null}$ \1\&{then}\5
\X543:Get a stored numeric or string token\X\6
\4\&{else} \&{begin} \37\C{we are done with this token list}\6
\\{end\_token\_list};\5
\&{goto} \37\\{restart};\C{resume previous level}\6
\&{end}\2\2\par
\U section~533.\fi

\M542. \P$\X542:Insert a suffix or text parameter and \&{goto} \\{restart}\X\S$%
\6
\&{begin} \37\&{if} $\\{cur\_sym}\G\\{text\_base}$ \1\&{then}\5
$\\{cur\_sym}\K\\{cur\_sym}-\\{param\_size}$;\C{$\\{param\_size}=\\{text%
\_base}-\\{suffix\_base}$}\2\6
$\\{begin\_token\_list}(\\{param\_stack}[\\{param\_start}+\\{cur\_sym}-(%
\\{suffix\_base})],\39\\{parameter})$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~541.\fi

\M543. \P$\X543:Get a stored numeric or string token\X\S$\6
\&{begin} \37$\\{cur\_cmd}\K\\{info}(\\{loc})$;\5
$\\{cur\_mod}\K\\{value}(\\{loc})$;\5
$\\{cur\_sym}\K0$;\6
\&{end}\par
\U section~541.\fi

\M544. All of the easy branches of \\{get\_next} have now been taken care of.
There is one more branch.

\Y\P$\4\X544:Move to next line of file, or \&{goto} \\{restart} if there is no
next line, or \&{return} if a \&{readterminal} line has finished\X\S$\6
\&{if} $\\{name}>1$ \1\&{then}\5
\X546:Read next line of file into \\{buffer}, or \&{goto} \\{restart} if the
file has ended\X\6
\4\&{else} \&{begin} \37\&{if} $\R\\{terminal\_input}$ \1\&{then}\C{%
\&{readterminal} line has ended}\6
\&{begin} \37$\\{cur\_cmd}\K\\{end\_read\_terminal}$;\5
$\\{cur\_mod}\K0$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{input\_ptr}>0$ \1\&{then}\C{text was inserted during error recovery}%
\6
\&{begin} \37\\{end\_file\_reading};\5
\&{goto} \37\\{restart};\C{resume previous level}\6
\&{end};\2\6
\&{if} $\\{selector}<\\{log\_only}$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{if} $\\{interaction}>\\{nonstop\_mode}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{limit}=\\{start}$ \1\&{then}\C{previous line was empty}%
\6
$\\{print\_nl}(\.{"(Please\ type\ a\ command\ or\ say\ \`end\')"})$;\2\6
\\{print\_ln};\5
$\\{first}\K\\{start}$;\5
$\\{prompt\_input}(\.{"*"})$;\C{input on-line into \\{buffer}}\6
$\\{limit}\K\\{last}$;\5
$\\{buffer}[\\{limit}]\K\.{"\%"}$;\5
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\6
\&{end}\6
\4\&{else} $\\{fatal\_error}(\.{"***\ (job\ aborted,\ no\ legal\ end\
found)"})$;\C{nonstop mode, which is intended for overnight batch processing,
		never waits for on-line input}\2\6
\&{end}\2\par
\U section~535.\fi

\M545. The global variable \\{force\_eof} is normally \\{false}; it is set %
\\{true}
by an \&{endinput} command.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{force\_eof}: \37\\{boolean};\C{should the next \&{input} be aborted
early?}\par
\fi

\M546. \P$\X546:Read next line of file into \\{buffer}, or \&{goto} \\{restart}
if the file has ended\X\S$\6
\&{begin} \37$\\{incr}(\\{line})$;\5
$\\{first}\K\\{start}$;\6
\&{if} $\R\\{force\_eof}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{input\_ln}(\\{cur\_file},\39\\{true})$ \1\&{then}\C{not
end of file}\6
\\{firm\_up\_the\_line}\C{this sets \\{limit}}\6
\4\&{else} $\\{force\_eof}\K\\{true}$;\2\6
\&{end};\2\6
\&{if} $\\{force\_eof}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{")"})$;\5
$\\{force\_eof}\K\\{false}$;\5
\\{update\_terminal};\C{show user that file has been read}\6
\\{end\_file\_reading};\C{resume previous level}\6
\\{check\_outer\_validity};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
$\\{buffer}[\\{limit}]\K\.{"\%"}\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\C{ready to read}\6
\&{end}\par
\U section~544.\fi

\M547. If the user has set the \\{pausing} parameter to some positive value,
and if nonstop mode has not been selected, each line of input is displayed
on the terminal and the transcript file, followed by `\.{=>}'.
\MF\ waits for a response. If the response is simply \\{carriage\_return}, the
line is accepted as it stands, otherwise the line typed is
used instead of the line in the file.

\Y\P\4\&{procedure}\1\  \37\\{firm\_up\_the\_line};\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{an index into \\{buffer}}\2\6
\&{begin} \37$\\{limit}\K\\{last}$;\6
\&{if} $(\\{internal}[\\{pausing}]>0)\W(\\{interaction}>\\{nonstop\_mode})$ \1%
\&{then}\6
\&{begin} \37\\{print\_ln};\5
\\{wake\_up\_terminal};\6
\&{if} $\\{start}<\\{limit}$ \1\&{then}\6
\&{for} $\|k\K\\{start}\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\2\6
$\\{first}\K\\{limit}$;\5
$\\{prompt\_input}(\.{"=>"})$;\C{wait for user response}\6
\&{if} $\\{last}>\\{first}$ \1\&{then}\6
\&{begin} \37\&{for} $\|k\K\\{first}\mathrel{\&{to}}\\{last}-1$ \1\&{do}\C{move
line down in buffer}\6
$\\{buffer}[\|k+\\{start}-\\{first}]\K\\{buffer}[\|k]$;\2\6
$\\{limit}\K\\{start}+\\{last}-\\{first}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\N548.  \[xx] Scanning macro definitions.
\MF\ has a variety of ways to tuck tokens away into token lists for later
use: Macros can be defined with \&{def}, \&{vardef}, \&{primarydef}, etc.;
repeatable code can be defined with \&{loop}, \&{for}, \&{forsuffixes};
and there's also \&{readterminal}. All such operations are handled
by the routines in this part of the program.

The modifier part of each command code is zero for the ``ending delimiters''
(i.e., for \&{enddef}, \&{od}, and \&{repeat}).

\Y\P\D \37$\\{start\_def}=1$\C{command modifier for \&{def}}\par
\P\D \37$\\{var\_def}=2$\C{command modifier for \&{vardef}}\par
\P\D \37$\\{primary\_def}=3$\C{command modifier for \&{primarydef}}\par
\P\D \37$\\{secondary\_def}=4$\C{command modifier for \&{secondarydef}}\par
\P\D \37$\\{tertiary\_def}=5$\C{command modifier for \&{tertiarydef}}\par
\P\D \37$\\{end\_def}=0$\C{command modifier for \&{enddef}}\par
\P\D \37$\\{start\_loop}=1$\C{command modifier for \&{loop}}\par
\P\D \37$\\{end\_loop}=0$\C{command modifier for \&{repeat}}\par
\P\D \37$\\{start\_for}=1$\C{command modifier for \&{for}}\par
\P\D \37$\\{start\_for\_suffixes}=2$\C{command modifier for \&{forsuffixes}}\par
\P\D \37$\\{end\_for}=0$\C{command modifier for \&{od}}\par
\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"def"},\39\\{macro\_def},\39\\{start\_def})$;\6
$\\{primitive}(\.{"vardef"},\39\\{macro\_def},\39\\{var\_def})$;\6
$\\{primitive}(\.{"primarydef"},\39\\{macro\_def},\39\\{primary\_def})$;\6
$\\{primitive}(\.{"secondarydef"},\39\\{macro\_def},\39\\{secondary\_def})$;\6
$\\{primitive}(\.{"tertiarydef"},\39\\{macro\_def},\39\\{tertiary\_def})$;\6
$\\{primitive}(\.{"enddef"},\39\\{macro\_def},\39\\{end\_def})$\7
$\\{primitive}(\.{"loop"},\39\\{loop\_repeat},\39\\{start\_loop})$;\6
$\\{primitive}(\.{"endloop"},\39\\{loop\_repeat},\39\\{end\_loop})$;\7
$\\{primitive}(\.{"for"},\39\\{iteration},\39\\{start\_for})$;\6
$\\{primitive}(\.{"forsuffixes"},\39\\{iteration},\39\\{start\_for%
\_suffixes})$;\6
$\\{primitive}(\.{"endfor"},\39\\{iteration},\39\\{end\_for})$;\par
\fi

\M549. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{macro\_def}: \37\&{case} $\mathbin{\&{mod}}$ \1\&{of}\6
\4\\{start\_def}: \37$\\{print}(\.{"def"})$;\6
\4\\{var\_def}: \37$\\{print}(\.{"vardef"})$;\6
\4\\{primary\_def}: \37$\\{print}(\.{"primarydef"})$;\6
\4\\{secondary\_def}: \37$\\{print}(\.{"secondarydef"})$;\6
\4\\{tertiary\_def}: \37$\\{print}(\.{"tertiarydef"})$;\6
\4\&{othercases} \37$\\{print}(\.{"enddef"})$\2\6
\&{endcases};\6
\4\\{loop\_repeat}: \37\&{if} $\mathbin{\&{mod}}=\\{start\_loop}$ \1\&{then}\5
$\\{print}(\.{"loop"})$\6
\4\&{else} $\\{print}(\.{"repeat"})$;\2\6
\4\\{iteration}: \37\&{if} $\mathbin{\&{mod}}=\\{start\_for}$ \1\&{then}\5
$\\{print}(\.{"for"})$\6
\4\&{else} \&{if} $\mathbin{\&{mod}}=\\{start\_for\_suffixes}$ \1\&{then}\5
$\\{print}(\.{"forsuffixes"})$\6
\4\&{else} $\\{print}(\.{"endfor"})$;\2\2\par
\fi

\M550. Different macro-absorbing operations have different syntaxes, but they
also have a lot in common. There is a list of special symbols that are to
be replaced by parameters tokens; there is a special command code that
ends the definition; the quotation conventions are identical.  Therefore
it makes sense to have most of the work done by a single subroutine. That
subroutine is called \\{scan\_toks}.

The first parameter to \\{scan\_toks} is the command code that will
terminate scanning (either \\{macro\_def}, \\{loop\_repeat}, \\{iteration},
or \\{end\_read\_terminal}).

The second parameter, \\{subst\_list}, points to a (possibly empty) list
of two-word nodes whose \\{info} and \\{value} fields specify symbol tokens
before and after replacement. The list will be returned to free storage
by \\{scan\_toks}.

The third parameter is simply appended to the token list that is built.
And the final parameter tells how many of the special operations
\.{\#\AT!}, \.{\AT!}, and \.{\AT!\#} are to be replaced by suffix parameters.
When such parameters are present, they are called \.{\%SUFFIX0},
\.{\%SUFFIX1}, and \.{\%SUFFIX2}.

\Y\P\4\&{function}\1\  \37$\\{scan\_toks}(\\{terminator}:\\{quarterword};\,\35%
\\{subst\_list},\39\\{tail\_end}:\\{pointer};\,\35\\{suffix\_count}:\\{small%
\_number})$: \37\\{pointer};\6
\4\&{label} \37$\\{done},\39\\{found}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{tail of the token list being built}\6
\|q: \37\\{pointer};\C{temporary for link management}\6
\\{balance}: \37\\{integer};\C{left delimiters minus right delimiters}\2\6
\&{begin} \37$\|p\K\\{temp\_head}$;\5
$\\{balance}\K1$;\5
$\\{link}(\\{temp\_head})\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}=\\{terminator}$ \1\&{then}\5
\X552:Adjust the balance; \&{goto} \\{done} if it's zero\X\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{macro\_special}$ \1\&{then}\5
\X555:Handle quoted symbols, \.{\#\AT!}, \.{\AT!}, or \.{\AT!\#}\X\6
\4\&{else} \&{if} $\\{cur\_sym}>0$ \1\&{then}\5
\X551:Substitute for \\{cur\_sym} if it's on the \\{subst\_list}\X;\2\2\2\6
\&{if} $\\{cur\_sym}>0$ \1\&{then}\6
\&{begin} \37$\|q\K\\{get\_avail}$;\5
$\\{info}(\|q)\K\\{cur\_sym}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|q\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|q)\K\\{cur\_mod}$;\5
$\\{info}(\|q)\K\\{cur\_cmd}$;\6
\&{end};\2\6
$\\{link}(\|p)\K\|q$;\5
$\|p\K\|q$;\6
\&{end};\2\6
\4\\{done}: \37$\\{link}(\|p)\K\\{tail\_end}$;\5
$\\{flush\_node\_list}(\\{subst\_list})$;\5
$\\{scan\_toks}\K\\{link}(\\{temp\_head})$;\6
\&{end};\par
\fi

\M551. \P$\X551:Substitute for \\{cur\_sym} if it's on the \\{subst\_list}\X\S$%
\6
\&{begin} \37$\|q\K\\{subst\_list}$;\6
\&{while} $\|q\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{info}(\|q)=\\{cur\_sym}$ \1\&{then}\6
\&{begin} \37$\\{cur\_sym}\K\\{value}(\|q)$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\4\\{found}: \37\&{end}\par
\U section~550.\fi

\M552. \P$\X552:Adjust the balance; \&{goto} \\{done} if it's zero\X\S$\6
\&{if} $\\{cur\_mod}>0$ \1\&{then}\5
$\\{incr}(\\{balance})$\6
\4\&{else} \&{begin} \37$\\{decr}(\\{balance})$;\6
\&{if} $\\{balance}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end}\2\par
\U section~550.\fi

\M553. Four commands are intended to be used only within macro texts: %
\&{quote},
\.{\#\AT!}, \.{\AT!}, and \.{\AT!\#}. They are variants of a single command
code called \\{macro\_special}.

\Y\P\D \37$\\{quote}=0$\C{\\{macro\_special} modifier for \&{quote}}\par
\P\D \37$\\{macro\_prefix}=1$\C{\\{macro\_special} modifier for \&{\#\AT!}}\par
\P\D \37$\\{macro\_at}=2$\C{\\{macro\_special} modifier for \&{\AT!}}\par
\P\D \37$\\{macro\_suffix}=3$\C{\\{macro\_special} modifier for \&{\AT!\#}}\par
\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"quote"},\39\\{macro\_special},\39\\{quote})$;\6
$\\{primitive}(\.{"\#@"},\39\\{macro\_special},\39\\{macro\_prefix})$;\6
$\\{primitive}(\.{"@"},\39\\{macro\_special},\39\\{macro\_at})$;\6
$\\{primitive}(\.{"@\#"},\39\\{macro\_special},\39\\{macro\_suffix})$;\par
\fi

\M554. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{macro\_special}: \37\&{case} $\mathbin{\&{mod}}$ \1\&{of}\6
\4\\{macro\_prefix}: \37$\\{print}(\.{"\#@"})$;\6
\4\\{macro\_at}: \37$\\{print\_char}(\.{"@"})$;\6
\4\\{macro\_prefix}: \37$\\{print}(\.{"@\#"})$;\6
\4\&{othercases} \37$\\{print}(\.{"quote"})$\2\6
\&{endcases};\par
\fi

\M555. \P$\X555:Handle quoted symbols, \.{\#\AT!}, \.{\AT!}, or \.{\AT!\#}\X\S$%
\6
\&{begin} \37\&{if} $\\{cur\_mod}=\\{quote}$ \1\&{then}\5
\\{get\_next}\6
\4\&{else} \&{if} $\\{cur\_mod}\L\\{suffix\_count}$ \1\&{then}\5
$\\{cur\_sym}\K\\{suffix\_base}-1+\\{cur\_mod}$;\2\2\6
\&{end}\par
\U section~550.\fi

\M556. Here's a simple example of the use of \\{scan\_toks}. It comes into
action shortly after `\&{loop}' has been scanned, and it returns a
list of the following tokens up until the next unmatched `\&{repeat}'.
We assume that \\{cur\_sym} points to the hash address of `\&{loop}' (or
whatever token has invoked this subroutine), so that an appropriate
error message can be given in case of runaways.

\Y\P\4\&{procedure}\1\  \37\\{scan\_loop};\6
\4\&{var} \37\|p: \37\\{pointer};\C{temporary pointer}\2\6
\&{begin} \37$\\{scanner\_status}\K\\{loop\_defining}$;\5
$\\{warning\_index}\K\\{cur\_sym}$;\5
$\|p\K\\{scan\_toks}(\\{loop\_repeat},\39\\{null},\39\\{repeat\_the\_loop},%
\390)$;\5
$\\{scanner\_status}\K\\{normal}$;\5
$\\{scan\_loop}\K\|p$;\6
\&{end};\par
\fi

\M557. The \\{repeat\_the\_loop} that is appended in place of `\&{repeat}' in
the \\{scan\_loop} subroutine is a token list consisting simply of the
\\{frozen\_end\_loop} token. This will come through \MF's scanner at the proper
time to cause the loop to be repeated.

(If the user tries some shenanigan like `\&{loop} \&{let} \&{repeat}',
he will be foiled by the \\{get\_symbol} routine, which keeps frozen
tokens unchanged. Furthermore the \\{frozen\_end\_loop} is an \&{outer}
token, so it won't be lost accidentally.) FIXTHIS so that it is!

\Y\P$\4\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}\S$\6
$\\{info}(\\{repeat\_the\_loop})\K\\{frozen\_end\_loop}$;\5
$\\{text}(\\{frozen\_end\_loop})\K\.{"repeat"}$;\par
\fi

\M558. Before we actually redefine a symbolic token, we need to clear away its
former value, if it was a variable. The following stronger version of
\\{get\_symbol} does that.

\Y\P\4\&{procedure}\1\  \37\\{get\_clear\_symbol};\2\6
\&{begin} \37\\{get\_symbol};\6
\&{if} $\\{cur\_cmd}=\\{name}$ \1\&{then}\6
\&{if} $\\{cur\_mod}\I\\{null}$ \1\&{then}\5
$\\{flush\_symbol}(\\{cur\_mod})$;\2\2\6
\&{end};\par
\fi

\M559. Here's another little subroutine; it checks that an equals sign
comes along at the proper place in a definition.

\Y\P\4\&{procedure}\1\  \37\\{check\_equals};\2\6
\&{begin} \37\&{if} $\\{cur\_cmd}\I\\{equals}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ =\ has\ been\ inserted"})$;\5
$\\{help5}(\.{"The\ next\ thing\ in\ this\ \`def\'\ should\ have\ been\ \`=%
\',"})$\6
$(\.{"because\ I\'ve\ already\ looked\ at\ the\ definition\ heading."})$\6
$(\.{"But\ don\'t\ worry;\ I\'ll\ pretend\ that\ an\ equals\ sign"})$\6
$(\.{"was\ present.\ Everything\ from\ here\ to\ \`enddef\'"})$\6
$(\.{"will\ be\ the\ replacement\ text\ of\ this\ macro."})$;\5
\\{back\_error};\6
\&{end};\2\6
\&{end}\par
\fi

\M560. A \&{primarydef}, \&{secondarydef}, or \&{tertiarydef} is rather easily
handled by a method very much like \\{scan\_loop}.  In this case there are
two parameters, which will be \.{\%EXPR0} and \.{\%EXPR1} (i.e.,
\\{expr\_base} and $\\{expr\_base}+1$).

\Y\P\4\&{procedure}\1\  \37\\{make\_op\_def};\6
\4\&{var} \37\|m: \37$\\{primary\_def}\to\\{tertiary\_def}$;\C{the type of
definition}\6
$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37$\|m\K\\{cur\_mod}$;\6
\\{get\_symbol};\5
$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{info}(\|p)\K\\{cur\_sym}$;\5
$\\{value}(\|p)\K\\{expr\_base}$;\6
\\{get\_clear\_symbol};\5
$\\{warning\_index}\K\\{cur\_sym}$;\6
\\{get\_symbol};\5
$\|q\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{info}(\|q)\K\\{cur\_sym}$;\5
$\\{value}(\|q)\K\\{expr\_base}+1$;\5
$\\{link}(\|q)\K\|p$;\6
\\{get\_next};\5
\\{check\_equals};\6
$\\{scanner\_status}\K\\{op\_defining}$;\5
$\|r\K\\{get\_avail}$;\5
$\\{ref\_count}(\|r)\K\\{null}$;\5
$\\{link}(\|r)\K\\{scan\_toks}(\\{macro\_def},\39\|q,\39\\{null},\390)$;\5
$\\{scanner\_status}\K\\{normal}$;\5
$\\{eq\_type}(\\{warning\_index})\K\\{op\_macro}-\\{primary\_def}+\|m$;\5
$\\{equiv}(\\{warning\_index})\K\|r$;\6
\&{end};\par
\fi

\M561. Parameters to macros are introduced by the keywords \&{expr},
\&{suffix}, \&{text}, and \&{primary}.

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"expr"},\39\\{param\_type},\39\\{expr\_base})$;\6
$\\{primitive}(\.{"suffix"},\39\\{param\_type},\39\\{suffix\_base})$;\6
$\\{primitive}(\.{"text"},\39\\{param\_type},\39\\{text\_base})$;\6
$\\{primitive}(\.{"primary"},\39\\{param\_type},\390)$;\par
\fi

\M562. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{param\_type}: \37\&{if} $\mathbin{\&{mod}}=\\{expr\_base}$ \1\&{then}\5
$\\{print}(\.{"expr"})$\6
\4\&{else} \&{if} $\mathbin{\&{mod}}=\\{suffix\_base}$ \1\&{then}\5
$\\{print}(\.{"suffix"})$\6
\4\&{else} \&{if} $\mathbin{\&{mod}}=\\{text\_base}$ \1\&{then}\5
$\\{print}(\.{"text"})$\6
\4\&{else} $\\{print}(\.{"primary"})$;\2\2\2\par
\fi

\M563. Now let's do the more complex processing associated with \&{def}
and \&{vardef}. When the following procedure is called, \\{cur\_mod}
should be either \\{start\_def} or \\{var\_def}.

\Y\P\X779:Declare the procedure called \\{check\_delimiter}\X\6
\4\&{procedure}\1\  \37\\{scan\_def};\6
\4\&{var} \37\|m: \37$\\{start\_def}\to\\{var\_def}$;\C{the type of definition}%
\6
\|n: \37$0\to3$;\C{the number of special suffix parameters}\6
\|k: \37$0\to\\{param\_size}$;\C{the total number of parameters}\6
\|c: \37$\\{general\_macro}\to\\{of\_macro}$;\C{the kind of macro we're
defining}\6
\|r: \37\\{pointer};\C{parameter-substitution list}\6
\|q: \37\\{pointer};\C{tail of the macro token list}\6
\|p: \37\\{pointer};\C{temporary storage}\2\6
\&{begin} \37$\|m\K\\{cur\_mod}$;\5
$\|c\K\\{general\_macro}$;\5
$\\{link}(\\{temp\_head})\K\\{null}$;\6
$\|q\K\\{get\_avail}$;\5
$\\{ref\_count}(\|q)\K\\{null}$;\5
$\|r\K\\{null}$;\6
\X564:Scan the token or variable to be defined; set \|n, \\{scanner\_status},
and \\{warning\_index}\X;\6
$\|k\K\|n$;\6
\&{if} $\\{cur\_cmd}=\\{left\_delimiter}$ \1\&{then}\5
\X565:Absorb delimited arguments, putting them into lists \|q and \|r\X\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{param\_type}$ \1\&{then}\6
\&{if} $\|m=\\{var\_def}$ \1\&{then}\5
\X567:Absorb undelimited arguments, putting them into list \|r\X;\2\2\2\6
\\{check\_equals};\5
$\\{link}(\|q)\K\\{get\_avail}$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{info}(\|q)\K\|c$;\5
$\\{link}(\|q)\K\\{scan\_toks}(\\{macro\_def},\39\|r,\39\\{null},\39\|n)$;\5
$\\{scanner\_status}\K\\{normal}$;\6
\&{end};\par
\fi

\M564. \P$\X564:Scan the token or variable to be defined; set \|n, \\{scanner%
\_status}, and \\{warning\_index}\X\S$\6
\&{if} $\|m=\\{start\_def}$ \1\&{then}\6
\&{begin} \37\\{get\_clear\_symbol};\5
$\\{warning\_index}\K\\{cur\_sym}$;\5
$\\{scanner\_status}\K\\{op\_defining}$;\5
$\|n\K0$;\5
$\\{eq\_type}(\\{warning\_index})\K\\{macro}$;\5
$\\{equiv}(\\{warning\_index})\K\|q$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|p\K\\{scan\_declared\_variable}$;\5
$\\{flush\_variable}(\\{equiv}(\\{info}(\|p)),\39\\{link}(\|p),\39\\{true})$;\5
$\\{warning\_index}\K\\{find\_variable}(\|p)$;\5
$\\{flush\_list}(\|p)$;\5
$\\{scanner\_status}\K\\{var\_defining}$;\5
$\|n\K2$;\6
\&{if} $\\{cur\_cmd}=\\{macro\_special}$ \1\&{then}\6
\&{if} $\\{cur\_mod}=\\{macro\_suffix}$ \1\&{then}\C{\.{\AT!\#}}\6
\&{begin} \37$\|n\K3$;\5
\\{get\_next};\6
\&{end};\2\2\6
$\\{type}(\\{warn\_index})\K\\{var\_macro}-2+\|n$;\5
$\\{value}(\\{warn\_index})\K\|q$;\6
\&{end}\2\par
\U section~563.\fi

\M565. \P$\X565:Absorb delimited arguments, putting them into lists \|q and \|r%
\X\S$\6
\1\&{repeat} \37$\\{l\_delim}\K\\{cur\_sym}$;\5
$\\{r\_delim}\K\\{cur\_mod}$;\5
\\{get\_next};\6
\&{if} $(\\{cur\_cmd}=\\{param\_type})\W(\\{cur\_mod}\G\\{expr\_base})$ \1%
\&{then}\5
$\\{base}\K\\{cur\_mod}$\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Missing\ parameter\ type;\ \`expr\'%
\ will\ be\ assumed"})$;\5
$\\{help1}(\.{"You\ should\'ve\ had\ \`expr\'\ or\ \`suffix\'\ or\ \`text\'\
here."})$;\5
\\{back\_error};\5
$\\{base}\K\\{expr\_base}$;\6
\&{end};\2\6
\X566:Absorb parameter tokens for type \\{base}\X;\6
$\\{check\_delimiter}(\\{l\_delim},\39\\{r\_delim})$;\5
\\{get\_next};\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{left\_delimiter}$;\2\par
\U section~563.\fi

\M566. \P$\X566:Absorb parameter tokens for type \\{base}\X\S$\6
\1\&{repeat} \37$\\{link}(\|q)\K\\{get\_avail}$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{info}(\|q)\K\\{base}+\|k$;\6
\\{get\_symbol};\5
$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|p)\K\\{base}+\|k$;\5
$\\{info}(\|p)\K\\{cur\_sym}$;\6
\&{if} $\|k=\\{param\_size}$ \1\&{then}\5
$\\{overflow}(\.{"parameter\ stack\ size"},\39\\{param\_size})$;\2\6
$\\{incr}(\|k)$;\5
$\\{link}(\|p)\K\|r$;\5
$\|r\K\|p$;\5
\\{get\_next};\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{comma}$\2\par
\U section~565.\fi

\M567. \P$\X567:Absorb undelimited arguments, putting them into list \|r\X\S$\6
\&{if} $\\{cur\_mod}\L\\{expr\_base}$ \1\&{then} \6
\&{begin} \37$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|p)\K\\{expr\_base}+\|n$;\6
\&{if} $\\{cur\_mod}=0$ \1\&{then}\5
$\|c\K\\{unary\_macro}$\ \&{else} $\|c\K\\{expr\_macro}$;\2\6
\\{get\_symbol};\5
$\\{info}(\|p)\K\\{cur\_sym}$;\5
$\\{link}(\|p)\K\|r$;\5
$\|r\K\|p$;\5
\\{get\_next};  \6
\&{if} $\|c=\\{expr\_macro}$ \1\&{then}  \6
\&{if} $\\{cur\_cmd}=$ \1\&{of} \&{then} \6
\&{begin} \37$\|c\K\\{of\_macro}$;\5
$\|p\K\\{get\_node}(\\{token\_node\_size})$;\5
$\\{value}(\|p)\K\\{expr\_base}+1+\|n$;\5
\\{fet\_symbol};\5
$\\{info}(\|p)\K\\{cur\_sym}$;\5
$\\{link}(\|p)\K\|r$;\5
$\|r\K\|p$;\5
\\{get\_next};\6
\&{end}; \6
\&{end} \par
\U section~563.\fi

\M568. The processing of \&{for} statements requires some of the machinery
of expressions, so we shall defer it until later. But there's one
more use of \\{scan\_toks} that we might as well deal with now.

The statement `\&{readterminal} \|m' defines \|m to be a parameterless
macro whose value is a token list formed from the next line typed
at the terminal. The following procedure comes into action after
\&{readterminal} has been scanned.

\Y\P\4\&{procedure}\1\  \37\\{read\_toks};\6
\4\&{var} \37\|m: \37\\{pointer};\C{hash address of symbolic token being
defined}\6
\|p: \37\\{pointer};\C{head of the macro list}\2\6
\&{begin} \37\\{get\_clear\_symbol};\5
$\|m\K\\{cur\_sym}$;\6
\&{if} $\\{interaction}\L\\{nonstop\_mode}$ \1\&{then}\5
$\\{fatal\_error}(\.{"***\ (cannot\ readterminal\ in\ nonstop\ modes)"})$;\2\6
\\{begin\_file\_reading};\5
$\\{name}\K1$;\5
$\\{prompt\_input}(\.{""})$;\5
$\\{limit}\K\\{last}$;\5
$\\{buffer}[\\{limit}]\K\.{"\%"}$;\5
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\6
$\|p\K\\{get\_avail}$;\5
$\\{ref\_count}(\|p)\K\\{null}$;\5
$\\{link}(\|p)\K\\{scan\_toks}(\\{end\_read\_terminal},\39\\{null},\39\\{null},%
\390)$;\5
$\\{eq\_type}(\|m)\K\\{macro}$;\5
$\\{equiv}(\|m)\K\|p$;\5
\\{end\_file\_reading};\6
\&{end};\par
\fi

\N569.  \[xx] Expanding the next token.
Only a few command codes $<\\{min\_command}$ can possibly be returned by
\\{get\_next}; in increasing order, they are
\\{input}, \\{if\_test}, \\{fi\_or\_else}, and \\{defined\_macro}.

\MF\ usually gets the next token of input by saying \\{get\_x\_next}. This is
like \\{get\_next} except that it keeps getting more tokens until
finding $\\{cur\_cmd}\G\\{min\_command}$. In other words, \\{get\_x\_next}
expands
macros and removes conditionals or input instructions that might be present.

It follows that \\{get\_x\_next} might invoke itself recursively. In fact,
there is massive recursion, since macro expansion can involve the
scanning of arbitrarily complex expressions, which in turn involve
macro expansion and conditionals.

The expression scanning routines to be considered later
communicate via the global quantities \\{cur\_type} and \\{cur\_exp};
we must be very careful to save and restore these quantities.

\Y\P\hbox{\4}\X575:Declare the procedure called \\{macro\_call}\X\6
\4\&{procedure}\1\  \37\\{pass\_text};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{start\_input};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{conditional};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_primary};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_secondary};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_tertiary};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_expression};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_suffix};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{scan\_text};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{get\_x\_next};\6
\4\&{var} \37\|p: \37\\{pointer};\C{for list manipulation}\6
\\{save\_exp}: \37\\{pointer};\C{a capsule to save \\{cur\_type} and \\{cur%
\_exp}}\2\6
\&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}<\\{min\_command}$ \1\&{then}\6
\&{begin} \37$\\{save\_exp}\K\\{stash\_cur\_exp}$;\6
\1\&{repeat} \37\X570:Expand the current token (and subsequent ones if needed)%
\X;\6
\\{get\_next};\6
\4\&{until}\5
$\\{cur\_cmd}\G\\{min\_command}$;\2\6
$\\{unstash\_cur\_exp}(\\{save\_exp})$;\C{that restores \\{cur\_type} and %
\\{cur\_exp}}\6
\&{end};\2\6
\&{end};\par
\fi

\M570. \P$\X570:Expand the current token (and subsequent ones if needed)\X\S$\6
\&{begin} \37\&{if} $\\{internal}[\\{tracing\_commands}]>1$ \1\&{then}\6
\&{if} $\\{cur\_cmd}\I\\{defined\_macro}$ \1\&{then}\5
$\\{show\_cmd\_mod}(\\{cur\_cmd},\39\\{cur\_mod})$;\2\2\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4\\{defined\_macro}: \37$\\{macro\_call}(\\{cur\_mod},\39\\{null},\39\\{cur%
\_sym})$;\6
\4\\{if\_test}: \37\\{conditional};\C{this procedure is discussed in part xx
below}\6
\4\\{fi\_or\_else}: \37\X600:Terminate the current conditional and skip to %
\&{fi}\X;\6
\4\\{input}: \37\X573:Initiate or terminate input from a file\X;\2\6
\&{endcases};\6
\&{end}\par
\U section~569.\fi

\M571. The processing of \&{input} involves the \\{start\_input} subroutine,
which will be declared later; the processing of \&{endinput} is trivial.

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"input"},\39\\{input},\390)$;\6
$\\{primitive}(\.{"endinput"},\39\\{input},\391)$;\par
\fi

\M572. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{input}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print}(\.{"input"})$\ \&{else} $\\{print}(\.{"endinput"})$;\2\par
\fi

\M573. \P$\X573:Initiate or terminate input from a file\X\S$\6
\&{if} $\\{cur\_mod}>0$ \1\&{then}\5
$\\{force\_eof}\K\\{true}$\6
\4\&{else} \\{start\_input}\2\par
\U section~570.\fi

\M574. Now let's consider the \\{macro\_call} procedure, which is used to start
up
all user-defined macros. Since the parameters to a macro might be expressions,
\\{macro\_call} is recursive.

The first parameter to \\{macro\_call} points to the reference count of the
token list that defines the macro. The second parameter contains any
arguments that have already been parsed (see below).  The third parameter
points to the symbolic token that names the macro. If the third parameter
is \\{null}, the macro was defined by \&{vardef}, so its name can be
reconstructed from the prefix and ``at'' arguments found within the
second parameter.

What is this second parameter? It's simply a linked list of one-word items,
whose \\{info} fields point to the arguments. In other words, if $\\{arg%
\_list}=\\{null}$,
no arguments have been scanned yet; otherwise $\\{info}(\\{arg\_list})$ points
to
the first scanned argument, and $\\{link}(\\{arg\_list})$ points to the list of
further arguments (if any).

Arguments of type \&{expr} are so-called capsules, which we will
discuss later when we concentrate on expressions; they can be
recognized because their \\{link} field is \\{null1}. Arguments of type
\&{suffix} and \&{text} are token lists without reference counts.

\fi

\M575. After argument scanning is complete, the arguments are moved to the
\\{param\_stack}. (They can't be put on that stack any sooner, because
the stack is growing and shrinking in unpredictable ways as more arguments
are being acquired.)  Then the macro body is fed to the scanner; i.e.,
the replacement text of the macro will be placed at the top of the \MF's
input stack, so that \\{get\_next} will proceed to read it next.

\Y\P$\4\X575:Declare the procedure called \\{macro\_call}\X\S$\6
\X577:Declare the procedure called \\{print\_macro\_name}\X\6
\X673:Declare the procedure called \\{print\_exp}\X\6
\X668:Declare the stashing/unstashing routines\X\6
\4\&{procedure}\1\  \37$\\{macro\_call}(\\{def\_ref},\39\\{arg\_list},\39%
\\{macro\_name}:\\{pointer})$;\C{invokes a user-defined control sequence}\6
\4\&{label} \37$\\{found},\39\\{done}$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{current node in the macro's token list}\6
$\|p,\39\|q$: \37\\{pointer};\C{for list manipulation}\6
\|n: \37\\{integer};\C{the number of arguments}\6
$\\{l\_delim},\39\\{r\_delim}$: \37\\{pointer};\C{a delimiter pair}\6
\\{balance}: \37\\{integer};\C{excess of \\{l\_delim} over \\{r\_delim}}\2\6
\&{begin} \37$\|r\K\\{link}(\\{def\_ref})$;\5
$\\{add\_ref}(\\{def\_ref})$;\6
\&{if} $\\{internal}[\\{tracing\_macros}]>0$ \1\&{then}\5
\X576:Show the text of the macro being expanded, and the existing arguments\X;%
\2\6
\&{if} $\\{arg\_list}=\\{null}$ \1\&{then}\5
$\|n\K0$\6
\4\&{else} \X578:Determine the number \|n of arguments already supplied, and
set \\{tail} to the tail of \\{arg\_list}\X;\2\6
\X579:Scan the remaining arguments, if any; set \|r to the first token of the
replacement text\X;\6
\X585:Feed the arguments and replacement text to the scanner\X;\6
\&{end};\par
\U section~569.\fi

\M576. \P$\X576:Show the text of the macro being expanded, and the existing
arguments\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
\\{print\_ln};\5
$\\{print\_macro\_name}(\\{arg\_list},\39\\{macro\_name})$;\5
$\\{show\_macro}(\\{def\_ref})$;\6
\&{if} $\\{arg\_list}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|n\K0$;\5
$\|p\K\\{arg\_list}$;\6
\1\&{repeat} \37$\|q\K\\{info}(\|p)$;\6
\&{if} $\\{link}(\|q)=\\{null1}$ \1\&{then}\5
$\\{print\_nl}(\.{"(\%EXPR"})$\ \&{else} $\\{print\_nl}(\.{"(\%SUFFIX"})$;\2\6
$\\{print\_int}(\|n)$;\5
$\\{print}(\.{")<-"})$;\6
\&{if} $\\{link}(\|q)=\\{null1}$ \1\&{then}\5
$\\{print\_exp}(\|q,\39\\{true})$\6
\4\&{else} $\\{print\_token\_list}(\|q,\39\\{null},\391000)$;\2\6
$\\{incr}(\|n)$;\5
$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\|p=\\{null}$;\2\6
\&{end};\2\6
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~575.\fi

\M577. \P$\X577:Declare the procedure called \\{print\_macro\_name}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_macro\_name}(\|a,\39\|n:\\{pointer})$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{they traverse the first part of %
\|a}\2\6
\&{begin} \37\&{if} $\|n\I\\{null}$ \1\&{then}\5
$\\{print}(\|n)$\6
\4\&{else} \&{begin} \37$\|p\K\\{info}(\|a)$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\5
$\\{print}(\\{info}(\\{link}(\|a)))$\6
\4\&{else} \&{begin} \37$\|q\K\|p$;\6
\&{while} $\\{link}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{link}(\|q)\K\\{info}(\\{link}(\|a))$;\5
$\\{show\_token\_list}(\|p,\39\\{null},\391000)$;\5
$\\{link}(\|q)\K\\{null}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\U section~575.\fi

\M578. \P$\X578:Determine the number \|n of arguments already supplied, and set
\\{tail} to the tail of \\{arg\_list}\X\S$\6
\&{begin} \37$\|n\K1$;\5
$\\{tail}\K\\{arg\_list}$;\6
\&{while} $\\{link}(\\{tail})\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|n)$;\5
$\\{tail}\K\\{link}(\\{tail})$;\6
\&{end};\2\6
\&{end}\par
\U section~575.\fi

\M579. \P$\X579:Scan the remaining arguments, if any; set \|r to the first
token of the replacement text\X\S$\6
$\\{cur\_cmd}\K\\{comma}+1$;\C{anything $\I\\{comma}$ will do}\6
\&{while} $\\{info}(\|r)\G\\{expr\_base}$ \1\&{do}\6
\&{begin} \37\X580:Scan the delimited argument represented by $\\{info}(\|r)$%
\X;\6
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}=\\{comma}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Too\ many\ arguments\ to\ "})$;\5
$\\{print\_macro\_name}(\\{arg\_list},\39\\{macro\_name})$;\5
$\\{print}(\.{";\ missing\ "})$;\5
$\\{print}(\\{text}(\\{r\_delim}))$;\5
$\\{print}(\.{"\ has\ been\ inserted"})$;\5
$\\{help3}(\.{"I\'m\ going\ to\ assume\ that\ the\ comma\ I\ just\ read\ was\
a"})$\6
$(\.{"right\ delimiter,\ and\ then\ I\'ll\ begin\ expanding\ the\ macro."})$\6
$(\.{"You\ might\ want\ to\ delete\ some\ tokens\ before\ continuing."})$;\5
\\{error};\6
\&{end};\2\6
\&{if} $\\{info}(\|r)\I\\{general\_macro}$ \1\&{then}\5
\X584:Scan undelimited argument(s)\X;\2\6
\4\\{done}: \37$\|r\K\\{link}(\|r)$\par
\U section~575.\fi

\M580. At this point, the reader will find it advisable to review the
explanation
of token list format that was presented earlier, paying special attention to
the conventions that apply only at the beginning of a macro's token list.

\Y\P$\4\X580:Scan the delimited argument represented by $\\{info}(\|r)$\X\S$\6
\&{if} $\\{cur\_cmd}\I\\{comma}$ \1\&{then}\6
\&{begin} \37\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}\I\\{left\_delim}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ argument\ to\ "})$;\5
$\\{print\_macro\_name}(\\{arg\_list},\39\\{macro\_name})$;\5
$\\{help3}(\.{"That\ macro\ has\ more\ parameters\ than\ you\ thought."})$\6
$(\.{"I\'ll\ continue\ by\ pretending\ that\ each\ missing\ argument"})$\6
$(\.{"is\ either\ zero\ or\ null."})$;\6
\&{if} $\\{info}(\|r)\G\\{suffix\_base}$ \1\&{then}\6
\&{begin} \37$\\{cur\_exp}\K\\{null}$;\5
$\\{cur\_type}\K\\{token\_list}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_exp}\K0$;\5
$\\{cur\_type}\K\\{known}$;\6
\&{end};\2\6
\\{back\_error};\5
$\\{cur\_cmd}\K\\{right\_delimiter}$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
$\\{l\_delim}\K\\{cur\_sym}$;\5
$\\{r\_delim}\K\\{cur\_mod}$;\6
\&{end};\2\6
\X582:Scan the argument represented by $\\{info}(\|r)$\X;\6
\4\\{found}: \37\X581:Append the current expression to \\{arg\_list}\X\par
\U section~579.\fi

\M581. A \&{suffix} or \&{text} parameter will be have been scanned as
a token list pointed to by \\{cur\_exp}, in which case we will have
$\\{cur\_type}=\\{token\_list}$.

\Y\P$\4\X581:Append the current expression to \\{arg\_list}\X\S$\6
\&{begin} \37$\|p\K\\{get\_avail}$;\6
\&{if} $\\{cur\_type}=\\{token\_list}$ \1\&{then}\5
$\\{info}(\|p)\K\\{cur\_exp}$\6
\4\&{else} $\\{info}(\|p)\K\\{stash\_cur\_exp}$;\2\6
\&{if} $\\{arg\_list}=\\{null}$ \1\&{then}\5
$\\{arg\_list}\K\|p$\6
\4\&{else} $\\{link}(\\{tail})\K\|p$;\2\6
$\\{tail}\K\|p$;\5
$\\{incr}(\|n)$;\6
\&{end}\par
\U sections~580 and~584.\fi

\M582. \P$\X582:Scan the argument represented by $\\{info}(\|r)$\X\S$\6
\&{if} $\\{info}(\|r)\G\\{text\_base}$ \1\&{then}\5
\X583:Scan a text parameter delimited by $\\{l\_delim},\\{r\_delim}$\X\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\6
\&{if} $\\{info}(\|r)\G\\{suffix\_base}$ \1\&{then}\5
\\{scan\_suffix}\6
\4\&{else} \\{scan\_expression};\2\6
\&{end};\2\par
\U section~580.\fi

\M583. \P$\X583:Scan a text parameter delimited by $\\{l\_delim},\\{r\_delim}$%
\X\S$\6
\&{begin} \37$\\{warning\_index}\K\|l$;\5
$\\{scanner\_status}\K\\{absorbing}$;\5
$\|p\K\\{temp\_head}$;\5
$\\{balance}\K1$;\5
$\\{link}(\\{temp\_head})\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}=\\{right\_delimiter}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_mod}=\|l$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{balance})$;\6
\&{if} $\\{balance}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{left\_delimiter}$ \1\&{then}\6
\&{if} $\\{cur\_mod}=\|r$ \1\&{then}\5
$\\{incr}(\\{balance})$;\2\2\2\6
$\\{link}(\|p)\K\\{cur\_tok}$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{done}: \37$\\{cur\_exp}\K\\{link}(\\{temp\_head})$;\5
$\\{cur\_type}\K\\{token\_list}$;\5
$\\{scanner\_status}\K\\{normal}$;\6
\&{end}\par
\U section~582.\fi

\M584. \P$\X584:Scan undelimited argument(s)\X\S$\6
\&{begin} \37\\{get\_x\_next}; \6
\&{case} $\\{info}(\|r)$ \1\&{of}\6
\4\\{primary\_macro}: \37\\{scan\_primary};\6
\4\\{secondary\_macro}: \37\\{scan\_secondary};\6
\4\\{tertiary\_macro}: \37\\{scan\_tertiary};\6
\4\\{expr\_macro}: \37\\{scan\_expression}; \6
\4\\{of\_macro}: \6
\&{begin} \37\\{scan\_expression};\5
$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{stash\_cur\_exp}$;\6
\&{if} $\\{arg\_list}=\\{null}$ \1\&{then}\5
$\\{arg\_list}\K\|p$\ \&{else} $\\{link}(\\{tail})\K\|p$;\2\6
$\\{tail}\K\|p$;\5
$\\{incr}(\|n)$;  \6
\&{if} $\\{cur\_cmd}\I$ \1\&{of} \&{then} \6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`of\'\ has\ been\ inserted\ for"})$;%
\5
$\\{print\_macro\_name}(\\{arg\_list},\39\\{macro\_name})$;\5
$\\{help1}(\.{"I\'ve\ got\ the\ first\ argument;\ will\ look\ now\ for\ the\
other."})$;\5
\\{back\_error};\6
\&{end};\5
\\{get\_x\_next};\5
\\{scan\_primary}; \6
\&{end} ; \6
\&{end} ;\C{there are no other cases}\6
\X581:Append the current expression to \\{arg\_list}\X;\6
\&{end} \par
\U section~579.\fi

\M585. Before we put a new token list on the input stack, it is wise to clean
off
all token lists that have recently been depleted. Then a user macro that ends
with a call to itself will not require unbounded stack space.

\Y\P$\4\X585:Feed the arguments and replacement text to the scanner\X\S$\6
\&{while} $\\{token\_state}\W(\\{loc}=\\{null})$ \1\&{do}\5
\\{end\_token\_list};\C{conserve stack space}\2\6
$\\{begin\_token\_list}(\\{def\_ref},\39\\{macro})$;\5
$\\{name}\K\\{macro\_name}$;\5
$\\{loc}\K\|r$;\6
\&{if} $\|n>0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{param\_ptr}+\|n>\\{max\_param\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_param\_stack}\K\\{param\_ptr}+\|n$;\C{FIXTHIS:where is %
\\{max\_param\_stack} declared?}\6
\&{if} $\\{max\_param\_stack}>\\{param\_size}$ \1\&{then}\5
$\\{overflow}(\.{"parameter\ stack\ size"},\39\\{param\_size})$;\2\6
\&{end};\2\6
$\|p\K\\{arg\_list}$;\6
\1\&{repeat} \37$\\{param\_stack}[\\{param\_ptr}]\K\\{info}(\|p)$;\5
$\\{incr}(\\{param\_ptr})$;\5
$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\|p=\\{null}$;\2\6
$\\{flush\_list}(\\{arg\_list})$;\6
\&{end}\2\par
\U section~575.\fi

\N586.  \[xx] Conditional processing.
[Again, don't read this, please!]
Let's consider now the way \&{if} commands are handled.

Conditions can be inside conditions, and this nesting has a stack
that is independent of other stacks.

Four global variables represent the top of the condition stack:
\\{cond\_ptr} points to pushed-down entries, if any; \\{cur\_if} tells whether
we are processing \&{if} or \&{elseif}; \\{if\_limit} specifies
the largest code of a \\{fi\_or\_else} command that is syntactically legal;
and \\{if\_line} is the line number at which the current conditional began.

If no conditions are currently in progress, the condition stack has the
special state $\\{cond\_ptr}=\\{null}$, $\\{if\_limit}=\\{normal}$, $\\{cur%
\_if}=0$, $\\{if\_line}=0$.
Otherwise \\{cond\_ptr} points to a two-word node; the \\{type}, \\{name%
\_type}, and
\\{link} fields of the first word contain \\{if\_limit}, \\{cur\_if}, and
\\{cond\_ptr} at the next level, and the second word contains the
corresponding \\{if\_line}.

\Y\P\D \37$\\{if\_node\_size}=2$\C{number of words in stack entry for
conditionals}\par
\P\D \37$\\{if\_line\_field}(\#)\S\\{mem}[\#+1].\\{int}$\par
\P\D \37$\\{if\_code}=1$\C{code for \&{if} being evaluated}\par
\P\D \37$\\{fi\_code}=2$\C{code for \&{fi}}\par
\P\D \37$\\{else\_code}=3$\C{code for \&{else}}\par
\P\D \37$\\{else\_if\_code}=4$\C{code for \&{elseif}}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cond\_ptr}: \37\\{pointer};\C{top of the condition stack}\6
\4\\{if\_limit}: \37$\\{normal}\to\\{or\_code}$;\C{upper bound on \\{fi\_or%
\_else} codes}\6
\4\\{cur\_if}: \37\\{small\_number};\C{type of conditional being worked on}\6
\4\\{if\_line}: \37\\{integer};\C{line where that conditional began}\par
\fi

\M587. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{cond\_ptr}\K\\{null}$;\5
$\\{if\_limit}\K\\{normal}$;\5
$\\{cur\_if}\K0$;\5
$\\{if\_line}\K0$;\par
\fi

\M588. \P$\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"fi"},\39\\{fi\_or\_else},\39\\{fi\_code})$;\5
$\\{primitive}(\.{"else"},\39\\{fi\_or\_else},\39\\{else\_code})$;\5
$\\{primitive}(\.{"elseif"},\39\\{fi\_or\_else},\39\\{else\_if\_code})$;\par
\fi

\M589. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{fi\_or\_else}: \37\&{if} $\\{chr\_code}=\\{fi\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"fi"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{else\_if\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"elseif"})$\6
\4\&{else} $\\{print\_esc}(\.{"else"})$;\2\2\par
\fi

\M590. When we skip conditional text, we keep track of the line number
where skipping began, for use in error messages.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{skip\_line}: \37\\{integer};\C{skipping began here}\par
\fi

\M591. Here is a procedure that ignores text until coming to an \&{elseif},
\&{else}, or \&{fi} at level zero of $\&{if}\ldots\&{fi}$
nesting. After it has acted, \\{cur\_mod} will indicate the token that
was found.

\Y\P\4\&{procedure}\1\  \37\\{pass\_text};\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|l: \37\\{integer};\5
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry FIXTHIS:needed?}\2\6
\&{begin} \37$\\{save\_scanner\_status}\K\\{scanner\_status}$;\5
$\\{scanner\_status}\K\\{skipping}$;\5
$\|l\K0$;\5
$\\{skip\_line}\K\\{line}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}=\\{fi\_or\_else}$ \1\&{then}\6
\&{begin} \37\&{if} $\|l=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
$\|l\K\|l-1$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{if\_test}$ \1\&{then}\5
$\|l\K\|l+1$;\2\2\6
\&{end};\2\6
\4\\{done}: \37$\\{scanner\_status}\K\\{save\_scanner\_status}$;\6
\&{end};\par
\fi

\M592. When we begin to process a new \&{if}, we set $\\{if\_limit}\K\\{if%
\_code}$; then
if \&{elseif} or \&{else} or \&{fi} occurs before the current \&{if}
condition has been evaluated, a colon will be inserted.
A construction like `\.{if fi}' would otherwise get \MF\ confused.

\Y\P$\4\X592:Push the condition stack\X\S$\6
\&{begin} \37$\|p\K\\{get\_node}(\\{if\_node\_size})$;\5
$\\{link}(\|p)\K\\{cond\_ptr}$;\5
$\\{type}(\|p)\K\\{if\_limit}$;\5
$\\{name\_type}(\|p)\K\\{cur\_if}$;\5
$\\{if\_line\_field}(\|p)\K\\{if\_line}$;\5
$\\{cond\_ptr}\K\|p$;\5
$\\{cur\_if}\K\\{cur\_chr}$;\5
$\\{if\_limit}\K\\{if\_code}$;\5
$\\{if\_line}\K\\{line}$;\6
\&{end}\par
\U section~595.\fi

\M593. \P$\X593:Pop the condition stack\X\S$\6
\&{begin} \37$\|p\K\\{cond\_ptr}$;\5
$\\{if\_line}\K\\{if\_line\_field}(\|p)$;\5
$\\{cur\_if}\K\\{name\_type}(\|p)$;\5
$\\{if\_limit}\K\\{type}(\|p)$;\5
$\\{cond\_ptr}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{if\_node\_size})$;\6
\&{end}\par
\U sections~595, 597, and~600.\fi

\M594. Here's a procedure that changes the \\{if\_limit} code corresponding to
a given value of \\{cond\_ptr}.

\Y\P\4\&{procedure}\1\  \37$\\{change\_if\_limit}(\|l:\\{small\_number};\,\35%
\|p:\\{pointer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|q: \37\\{pointer};\2\6
\&{begin} \37\&{if} $\|p=\\{cond\_ptr}$ \1\&{then}\5
$\\{if\_limit}\K\|l$\C{that's the easy case}\6
\4\&{else} \&{begin} \37$\|q\K\\{cond\_ptr}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{confusion}(\.{"if"})$;\2\6
\&{if} $\\{link}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{type}(\|q)\K\|l$;\5
\&{return};\6
\&{end};\2\6
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M595. A condition is started when the \\{expand} procedure encounters
an \\{if\_test} command; in that case \\{expand} reduces to \\{conditional},
which is a recursive procedure.

\Y\P\4\&{procedure}\1\  \37\\{conditional};\6
\4\&{label} \37$\\{exit},\39\\{common\_ending}$;\6
\4\&{var} \37\|b: \37\\{boolean};\C{is the condition true?}\6
\|r: \37$\.{"<"}\to\.{">"}$;\C{relation to be evaluated}\6
$\|m,\39\|n$: \37\\{integer};\C{to be tested against the second operand}\6
$\|p,\39\|q$: \37\\{pointer};\C{for traversing token lists in \.{\\ifx} tests}\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry}\6
\\{save\_cond\_ptr}: \37\\{pointer};\C{\\{cond\_ptr} corresponding to this
conditional}\6
\\{this\_if}: \37\\{small\_number};\C{type of this conditional}\2\6
\&{begin} \37\X592:Push the condition stack\X;\ $\\{save\_cond\_ptr}\K\\{cond%
\_ptr}$;\5
$\\{this\_if}\K\\{cur\_chr}$;\6
\X598:Set \|b to the value of a boolean condition\X;\6
\&{if} $\\{tracing\_commands}>1$ \1\&{then}\5
\X599:Display the value of \|b\X;\2\6
\&{if} $\|b$ \1\&{then}\6
\&{begin} \37$\\{change\_if\_limit}(\\{else\_code},\39\\{save\_cond\_ptr})$;\5
\&{return};\C{wait for \.{\\else} or \.{\\fi}}\6
\&{end};\2\6
\X597:Skip to \&{elseif} or \&{else} or \&{fi}, then \&{goto} \\{common}%
\\{ending}\X;\6
\4\\{common\_ending}: \37\&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
\X593:Pop the condition stack\X\6
\4\&{else} $\\{if\_limit}\K\\{fi\_code}$;\C{wait for \&{fi}}\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M596. In a construction like `\.{\\if\iftrue abc\else d\fi}', the first \.{%
\\else}
that we come to after learning that the \.{\\if} is false is not the
\.{\\else} we're looking for.

\fi

\M597. \P$\X597:Skip to \&{elseif} or \&{else} or \&{fi}, then \&{goto} %
\\{common}\\{ending}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\\{pass\_text};\6
\&{if} $\\{cond\_ptr}=\\{save\_cond\_ptr}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_chr}\I\\{or\_code}$ \1\&{then}\5
\&{goto} \37\\{common\_ending};\2\6
$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_esc}(\.{"or"})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this;\ it\ doesn\'t\ match\ any\ \\if."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
\X593:Pop the condition stack\X;\2\2\6
\&{end}\2\par
\U section~595.\fi

\M598. \P$\X598:Set \|b to the value of a boolean condition\X\S$\6
$\\{FIXTHIS}!$\par
\U section~595.\fi

\M599. \P$\X599:Display the value of \|b\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\6
\&{if} $\|b$ \1\&{then}\5
$\\{print}(\.{"\{true\}"})$\ \&{else} $\\{print}(\.{"\{false\}"})$;\2\6
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~595.\fi

\M600. The processing of conditionals is complete except for the following
code, which is actually part of \\{expand}. It comes into play when
\&{elseif}, \&{else}, or \&{fi} is scanned.

\Y\P$\4\X600:Terminate the current conditional and skip to \&{fi}\X\S$\6
\&{if} $\\{cur\_chr}>\\{if\_limit}$ \1\&{then}\6
\&{if} $\\{if\_limit}=\\{if\_code}$ \1\&{then}\C{condition not yet evaluated}\6
\&{begin} \37\\{back\_input};\5
$\\{cur\_sym}\K\\{frozen\_colon}$;\5
\\{back\_input};\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_cmd\_mod}(\\{fi\_or\_else},\39\\{cur\_chr})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this;\ it\ doesn\'t\ match\ any\ if."})$;\5
\\{error};\6
\&{end}\2\6
\4\&{else} \&{begin} \37\&{while} $\\{cur\_chr}\I\\{fi\_code}$ \1\&{do}\5
\\{pass\_text};\C{skip to \&{fi}}\2\6
\X593:Pop the condition stack\X;\6
\&{end}\2\par
\U section~570.\fi

\N601.  \[xx] File names.
The bane of portability is the existence of file names.
Besides the fact that different operating systems treat files in different
ways,
we must cope with the fact that completely different naming conventions
are used. The following programs show what is required for one particular
operating system; similar routines for other systems are not difficult
to devise.

\MF\ assumes that a file name has three parts: the name proper; its
``extension''; and a ``file area'' where it is found in an external file
system.  The extension of an input file is assumed to be
`\.{.mf}' unless otherwise specified; it is `\.{.log}' on the
transcript file that records each run of \MF; it is `\.{.tfm}' on the font
metric files that describe characters in the fonts \MF\ creates; it is
`\.{.gf}' on the output files that specify generic font information; and it
is `\.{.base}' on the base files written by \.{INIMF} to initialize \MF.
The file area can be arbitrary on input files, but files are usually
output to the user's current area.  If an input file cannot be
found on the specified area, \MF\ will look for it on a special system
area; this special area is intended for commonly used input files.

Simple uses of \MF\ refer only to file names that have no explicit
extension or area. For example, a person usually says `\.{input} \.{cmr10}'
instead of `\.{input} \.{cmr10.new}'. Simple file
names are best, because they make the \MF\ source files portable;
whenever a file name consists entirely of letters and digits, it should be
treated in the same way by all implementations of \MF. However, users
need the ability to refer to other files in their environment, especially
when responding to error messages concerning unopenable files; therefore
we want to let them use the syntax that appears in their favorite
operating system.

\fi

\M602. \MF\ uses the same conventions that have proved to be satisfactory for
\TeX. In order to isolate the system-dependent aspects of file names, the
system-independent parts of \MF\ make use of three system-dependent
procedures that are called \\{begin\_name}, \\{more\_name}, and \\{end\_name}.
In
essence, if the user-specified characters of the file name are $c_1\ldots c_n$,
the system-independent driver program does the operations
$$\\{begin\_name};\,\\{more\_name}(c_1);\ldots\,;\\{more\_name}(c_n);
\,\\{end\_name}.$$
These three procedures communicate with each other via global variables.
Afterwards the file name will appear in the string pool as three strings
called \\{cur\_name}\penalty10000\hskip-.05em,
\\{cur\_area}, and \\{cur\_ext}; the latter two are null (i.e.,
\.{""}), unless they were explicitly specified by the user.

Actually the situation is slightly more complicated, because \MF\ needs
to know when the file name ends. The \\{more\_name} routine is a function
(with side effects) that returns \\{true} on the calls \\{more\_name}$(c_1)$,
\dots, \\{more\_name}$(c_{n-1})$. The final call \\{more\_name}$(c_n)$
returns \\{false}; or, it returns \\{true} and the token following $c_n$ is
something like `\.{begingroup}' (i.e., not a character). In other words,
\\{more\_name} is supposed to return \\{true} unless it is sure that the
file name has been completely scanned; and \\{end\_name} is supposed to be able
to finish the assembly of \\{cur\_name}, \\{cur\_area}, and \\{cur\_ext}
regardless of
whether $\\{more\_name}(c_n)$ returned \\{true} or \\{false}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_name}: \37\\{str\_number};\C{name of file just scanned}\6
\4\\{cur\_area}: \37\\{str\_number};\C{file area just scanned, or \.{""}}\6
\4\\{cur\_ext}: \37\\{str\_number};\C{file extension just scanned, or \.{""}}%
\par
\fi

\M603. The file names we shall deal with have the following structure:
If the name contains `\.>' or `\.:', the file area consists of all characters
up to and including the final such character; otherwise the file area is null.
If the remaining file name contains `\..', the file extension consists of all
such characters from the first `\..' to the end, otherwise the file extension
is null.

We can scan such file names easily by using two global variables that keep
track
of the occurrences of area and extension delimiters:

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{area\_delimiter}: \37\\{pool\_pointer};\C{the most recent `\.>' or `\.:',
if any}\6
\4\\{ext\_delimiter}: \37\\{pool\_pointer};\C{the relevant `\..', if any}\par
\fi

\M604. Input files that can't be found in the user's area may appear in a
standard
system area called \\{MF\_area}.
This system area name will, of course, vary from place to place.

\Y\P\D \37$\\{MF\_area}\S\.{"MFinputs:"}$\par
\fi

\M605. Here now is the first of the system-dependent routines for file name
scanning.

\Y\P\4\&{procedure}\1\  \37\\{begin\_name};\2\6
\&{begin} \37$\\{area\_delimiter}\K0$;\5
$\\{ext\_delimiter}\K0$;\6
\&{end};\par
\fi

\M606. And here's the second.

\Y\P\4\&{function}\1\  \37$\\{more\_name}(\|c:\\{ASCII\_code})$: \37%
\\{boolean};\2\6
\&{begin} \37\&{if} $\|c=\.{"\ "}$ \1\&{then}\5
$\\{more\_name}\K\\{false}$\6
\4\&{else} \&{begin} \37\&{if} $(\|c=\.{">"})\V(\|c=\.{":"})$ \1\&{then}\6
\&{begin} \37$\\{area\_delimiter}\K\\{pool\_ptr}$;\5
$\\{ext\_delimiter}\K0$;\6
\&{end}\6
\4\&{else} \&{if} $(\|c=\.{"."})\W(\\{ext\_delimiter}=0)$ \1\&{then}\5
$\\{ext\_delimiter}\K\\{pool\_ptr}$;\2\2\6
$\\{str\_room}(1)$;\5
$\\{append\_char}(\|c)$;\C{contribute \|c to the current string}\6
$\\{more\_name}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M607. The third.

\Y\P\4\&{procedure}\1\  \37\\{end\_name};\2\6
\&{begin} \37\&{if} $\\{str\_ptr}+3>\\{max\_strings}$ \1\&{then}\5
$\\{overflow}(\.{"number\ of\ strings"},\39\\{max\_strings}-\\{init\_str%
\_ptr})$;\2\6
\&{if} $\\{area\_delimiter}=0$ \1\&{then}\5
$\\{cur\_area}\K\.{""}$\6
\4\&{else} \&{begin} \37$\\{cur\_area}\K\\{str\_ptr}$;\5
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{area\_delimiter}+1$;\6
\&{end};\2\6
\&{if} $\\{ext\_delimiter}=0$ \1\&{then}\6
\&{begin} \37$\\{cur\_ext}\K\.{""}$;\5
$\\{cur\_name}\K\\{make\_string}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_name}\K\\{str\_ptr}$;\5
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{ext\_delimiter}$;\5
$\\{cur\_ext}\K\\{make\_string}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M608. Conversely, here is a routine that takes three strings and prints a file
name that might have produced them. (The routine is system dependent, because
some operating systems put the file area last instead of first.)

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_file\_name}(\|n,\39\|a,\39\|e:\\{integer})$;%
\2\6
\&{begin} \37$\\{print}(\|a)$;\5
$\\{print}(\|n)$;\5
$\\{print}(\|e)$;\6
\&{end};\par
\fi

\M609. Another system-dependent routine is needed to convert three \MF\ strings
to the \\{name\_of\_file} value that is used to open files. The present code
allows both lowercase and uppercase letters in the file name.

\Y\P\D \37$\\{append\_to\_name}(\#)\S$\1\6
\&{begin} \37$\|c\K\#$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_of\_file}[\|k]\K\\{xchr}[\|c]$;\2\6
\&{end}\2\par
\Y\P\4\&{procedure}\1\  \37$\\{pack\_file\_name}(\|n,\39\|a,\39\|e:\\{str%
\_number})$;\6
\4\&{var} \37\|k: \37\\{integer};\C{number of positions filled in \\{name\_of%
\_file}}\6
\|c: \37\\{ASCII\_code};\C{character being packed}\6
\|j: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37$\|k\K0$;\6
\&{for} $\|j\K\\{str\_start}[\|a]\mathrel{\&{to}}\\{str\_start}[\|a+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{for} $\|j\K\\{str\_start}[\|n]\mathrel{\&{to}}\\{str\_start}[\|n+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{for} $\|j\K\\{str\_start}[\|e]\mathrel{\&{to}}\\{str\_start}[\|e+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_length}\K\|k$\ \&{else} $\\{name\_length}\K\\{file\_name\_size}$;\2\6
\&{for} $\|k\K\\{name\_length}+1\mathrel{\&{to}}\\{file\_name\_size}$ \1\&{do}\5
$\\{name\_of\_file}[\|k]\K\.{\'\ \'}$;\2\6
\&{end};\par
\fi

\M610. A messier routine is also needed, since base file names must be scanned
before \MF's string mechanism has been initialized. We shall use the
global variable \\{MF\_base\_default} to supply the text for default system
areas
and extensions related to base files.

\Y\P\D \37$\\{base\_default\_length}=21$\C{length of the \\{MF\_base\_default}
string}\par
\P\D \37$\\{base\_area\_length}=11$\C{length of its area part}\par
\P\D \37$\\{base\_ext\_length}=5$\C{length of its `\.{.base}' part}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{MF\_base\_default}: \37\&{packed} \37\&{array} $[1\to\\{base\_default%
\_length}]$ \1\&{of}\5
\\{char};\2\par
\fi

\M611. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{MF\_base\_default}\K\.{\'TeXformats:PLAIN.base\'}$;\par
\fi

\M612. \P$\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $\\{base\_default\_length}>\\{file\_name\_size}$ \1\&{then}\5
$\\{bad}\K31$;\2\par
\fi

\M613. Here is the messy routine that was just mentioned. It sets \\{name\_of%
\_file}
from the first \|n characters of \\{MF\_base\_default}, followed by
$\\{buffer}[\|a\to\|b]$, followed by the last \\{base\_ext\_length} characters
of
\\{MF\_base\_default}.

We dare not give error messages here, since \MF\ calls this routine before
the \\{error} routine is ready to roll. Instead, we simply drop excess
characters,
since the error will be detected in another way when a strange file name
isn't found.

\Y\P\4\&{procedure}\1\  \37$\\{pack\_buffered\_name}(\|n:\\{small\_number};\,%
\35\|a,\39\|b:\\{integer})$;\6
\4\&{var} \37\|k: \37\\{integer};\C{number of positions filled in \\{name\_of%
\_file}}\6
\|c: \37\\{ASCII\_code};\C{character being packed}\6
\|j: \37\\{integer};\C{index into \\{buffer} or \\{MF\_base\_default}}\2\6
\&{begin} \37\&{if} $\|n+\|b-\|a+1+\\{base\_ext\_length}>\\{file\_name\_size}$ %
\1\&{then}\5
$\|b\K\|a+\\{file\_name\_size}-\|n-1-\\{base\_ext\_length}$;\2\6
$\|k\K0$;\6
\&{for} $\|j\K1\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{append\_to\_name}(\\{xord}[\\{MF\_base\_default}[\|j]])$;\2\6
\&{for} $\|j\K\|a\mathrel{\&{to}}\|b$ \1\&{do}\5
$\\{append\_to\_name}(\\{buffer}[\|j])$;\2\6
\&{for} $\|j\K\\{base\_default\_length}-\\{base\_ext\_length}+1\mathrel{\&{to}}%
\\{base\_default\_length}$ \1\&{do}\5
$\\{append\_to\_name}(\\{xord}[\\{MF\_base\_default}[\|j]])$;\2\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_length}\K\|k$\ \&{else} $\\{name\_length}\K\\{file\_name\_size}$;\2\6
\&{for} $\|k\K\\{name\_length}+1\mathrel{\&{to}}\\{file\_name\_size}$ \1\&{do}\5
$\\{name\_of\_file}[\|k]\K\.{\'\ \'}$;\2\6
\&{end};\par
\fi

\M614. Here is the only place we use \\{pack\_buffered\_name}. This part of the
program
becomes active when a ``virgin'' \MF\ is trying to get going, just after
the preliminary initialization, or when the user is substituting another
base file by typing `\.\&' after the initial `\.{**}' prompt.  The buffer
contains the first line of input in $\\{buffer}[\\{loc}\to(\\{last}-1)]$, where
$\\{loc}<\\{last}$ and $\\{buffer}[\\{loc}]\I\.{"\ "}$.

\Y\P$\4\X614:Declare the function called \\{open\_base\_file}\X\S$\6
\4\&{function}\1\  \37\\{open\_base\_file}: \37\\{boolean};\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37\|j: \37$0\to\\{buf\_size}$;\C{the first space after the file
name}\2\6
\&{begin} \37\&{if} $\\{buffer}[\\{loc}]=\.{"\&"}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{loc})$;\5
$\|j\K\\{loc}$;\5
$\\{buffer}[\\{last}]\K\.{"\ "}$;\6
\&{while} $\\{buffer}[\|j]\I\.{"\ "}$ \1\&{do}\5
$\\{incr}(\|j)$;\2\6
$\\{pack\_buffered\_name}(0,\39\\{loc},\39\|j-1)$;\C{try first without the
system file area}\6
\&{if} $\\{w\_open\_in}(\\{base\_file})$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\|j$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
$\\{pack\_buffered\_name}(\\{base\_area\_length},\39\\{loc},\39\|j-1)$;\C{now
try the system base file area}\6
\&{if} $\\{w\_open\_in}(\\{base\_file})$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\|j$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'Sorry,\ I\ can\'}\.{\'t\ find\ that\ base;\'},\39\.{\'\
will\ try\ PLAIN.\'})$;\6
\&{end};\C{now pull out all the stops: try for the system \.{PLAIN} file}\2\6
$\\{pack\_buffered\_name}(\\{base\_default\_length}-\\{base\_ext\_length},\391,%
\390)$;\6
\&{if} $\R\\{w\_open\_in}(\\{base\_file})$ \1\&{then}\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'I\ can\'}\.{\'t\ find\ the\ PLAIN\ base\ file!\'})$;\5
$\\{open\_base\_file}\K\\{false}$;\5
\&{return};\6
\&{end};\2\6
\4\\{found}: \37$\\{open\_base\_file}\K\\{true}$;\6
\4\\{exit}: \37\&{end};\par
\U section~791.\fi

\M615. Operating systems often make it possible to determine the exact name
(and
possible version number) of a file that has been opened. The following routine,
which simply makes a \MF\ string from the value of \\{name\_of\_file}, should
ideally be changed to deduce the full name of file~\|f, if it is
possible to do this in a \PASCAL\ program.

\Y\P\4\&{function}\1\  \37\\{make\_name\_string}: \37\\{str\_number};\6
\4\&{var} \37\|k: \37$1\to\\{file\_name\_size}$;\C{index into \\{name\_of%
\_file}}\2\6
\&{begin} \37$\\{str\_room}(\\{name\_length})$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{name\_length}$ \1\&{do}\5
$\\{append\_char}(\\{xord}[\\{name\_of\_file}[\|k]])$;\2\6
$\\{make\_name\_string}\K\\{make\_string}$;\6
\&{end};\6
\4\&{function}\1\  \37$\\{a\_make\_name\_string}(\mathop{\&{var}}\|f:\\{alpha%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{a\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\6
\4\&{function}\1\  \37$\\{b\_make\_name\_string}(\mathop{\&{var}}\|f:\\{byte%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{b\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\6
\4\&{function}\1\  \37$\\{w\_make\_name\_string}(\mathop{\&{var}}\|f:\\{word%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{w\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\par
\fi

\M616. Now let's consider the routines by which \MF\ deals with file names
in a system-independent manner.  First comes a procedure that looks for a
file name in the input by taking the information from the input buffer.
(We can't use \\{get\_next}, because the conversion to tokens would
destroy necessary information.)

\Y\P\4\&{procedure}\1\  \37\\{scan\_file\_name};\6
\4\&{label} \37\\{done};\2\6
\&{begin} \37\\{begin\_name};\6
\&{while} $\\{buffer}[\\{loc}]=\.{"\ "}$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{loc}=\\{limit}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\R\\{more\_name}(\\{buffer}[\\{loc}])$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\4\\{done}: \37\\{end\_name};\6
\&{end};\par
\fi

\M617. The global variable \\{job\_name} contains the file name that was first
\&{input} by the user. This name is extended by `\.{log}' and `\.{gf}'
and `\.{base}' and `\.{tfm}' in order to make the names of \MF's output files.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{job\_name}: \37\\{str\_number};\C{principal file name}\par
\fi

\M618. Initially $\\{job\_name}=0$; it becomes nonzero as soon as the true name
is known.
We have $\\{job\_name}=0$ if and only if the `\.{log}' file has not been
opened,
except of course for a short time just after \\{job\_name} has become nonzero.

\Y\P$\4\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{job\_name}\K0$;\par
\fi

\M619. Here is a routine that manufactures the output file names, assuming that
$\\{job\_name}\I0$. It ignores and changes the current settings of \\{cur%
\_area}
and \\{cur\_ext}.

\Y\P\D \37$\\{pack\_cur\_name}\S\\{pack\_file\_name}(\\{cur\_name},\39\\{cur%
\_area},\39\\{cur\_ext})$\par
\Y\P\4\&{procedure}\1\  \37$\\{pack\_job\_name}(\|s:\\{str\_number})$;\C{$\|s=%
\.{".log"}$, \.{".gf"}, or 	\.{".base"}}\2\6
\&{begin} \37$\\{cur\_area}\K\.{""}$;\5
$\\{cur\_ext}\K\|s$;\5
$\\{cur\_name}\K\\{job\_name}$;\5
\\{pack\_cur\_name};\6
\&{end};\par
\fi

\M620. If some trouble arises when \MF\ tries to open a file, the following
routine calls upon the user to supply another file name. Parameter~\|s
is used in the error message to identify the type of file; parameter~\|e
is the default extension if none is given. Upon exit from the routine,
variables \\{cur\_name}, \\{cur\_area}, \\{cur\_ext}, and \\{name\_of\_file}
are
ready for another attempt at file opening.

\Y\P\4\&{procedure}\1\  \37$\\{prompt\_file\_name}(\|s,\39\|e:\\{str%
\_number})$;\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\2\6
\&{begin} \37\&{if} $\\{interaction}=\\{scroll\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
\&{if} $\|s=\.{"input\ file\ name"}$ \1\&{then}\5
$\\{print\_err}(\.{"I\ can\'t\ find\ file\ \`"})$\6
\4\&{else} $\\{print\_err}(\.{"I\ can\'t\ write\ on\ file\ \`"})$;\2\6
$\\{print\_file\_name}(\\{cur\_name},\39\\{cur\_area},\39\\{cur\_ext})$;\5
$\\{print}(\.{"\'."})$;\6
\&{if} $\|e=\.{".mf"}$ \1\&{then}\5
\\{show\_context};\2\6
$\\{print\_nl}(\.{"Please\ type\ another\ "})$;\5
$\\{print}(\|s)$;\6
\&{if} $\\{interaction}<\\{scroll\_mode}$ \1\&{then}\5
$\\{fatal\_error}(\.{"***\ (job\ aborted,\ file\ error\ in\ nonstop\ mode)"})$;%
\2\6
\\{clear\_terminal};\5
$\\{prompt\_input}(\.{":\ "})$;\5
\X621:Scan file name in the buffer\X;\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\|e$;\2\6
\\{pack\_cur\_name};\6
\&{end};\par
\fi

\M621. \P$\X621:Scan file name in the buffer\X\S$\6
\&{begin} \37\\{begin\_name};\5
$\|k\K\\{first}$;\6
\&{while} $(\\{buffer}[\|k]=\.{"\ "})\W(\|k<\\{last})$ \1\&{do}\5
$\\{incr}(\|k)$;\2\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|k=\\{last}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\R\\{more\_name}(\\{buffer}[\|k])$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\|k)$;\6
\&{end};\2\6
\4\\{done}: \37\\{end\_name};\6
\&{end}\par
\U section~620.\fi

\M622. Here's an example of how these conventions are used. We shall use the
macro \\{ensure\_gf\_open} when it is time to ship out a box of stuff.

\Y\P\D \37$\\{ensure\_gf\_open}\S$\1\6
\&{if} $\\{output\_file\_name}=0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
$\\{pack\_job\_name}(\.{".gf"})$;\6
\&{while} $\R\\{b\_open\_out}(\\{gf\_file})$ \1\&{do}\5
$\\{prompt\_file\_name}(\.{"file\ name\ for\ output"},\39\.{".gf"})$;\2\6
$\\{output\_file\_name}\K\\{b\_make\_name\_string}(\\{gf\_file})$;\6
\&{end}\2\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{gf\_file}: \37\\{byte\_file};\C{the generic font output goes here}\6
\4\\{output\_file\_name}: \37\\{str\_number};\C{full name of the output file}\6
\4\\{log\_name}: \37\\{str\_number};\C{full name of the log file}\par
\fi

\M623. \P$\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{output\_file\_name}\K0$;\par
\fi

\M624. The \\{open\_log\_file} routine is used to open the transcript file and
to help
it catch up to what has previously been printed on the terminal.

\Y\P\4\&{procedure}\1\  \37\\{open\_log\_file};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{previous %
\\{selector} setting}\6
\|k: \37$0\to\\{buf\_size}$;\C{index into \\{months} and \\{buffer}}\6
\|l: \37$0\to\\{buf\_size}$;\C{end of first input line}\6
\|m: \37\\{integer};\C{the current month}\6
\\{months}: \37\&{packed} \37\&{array} $[1\to36]$ \1\&{of}\5
\\{char};\C{abbreviations of month names}\2\2\6
\&{begin} \37$\\{old\_setting}\K\\{selector}$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
$\\{job\_name}\K\.{"mfput"}$;\2\6
$\\{pack\_job\_name}(\.{".log"})$;\6
\&{while} $\R\\{a\_open\_out}(\\{log\_file})$ \1\&{do}\5
\X625:Try to get a different log file name\X;\2\6
$\\{log\_name}\K\\{a\_make\_name\_string}(\\{log\_file})$;\5
$\\{selector}\K\\{log\_only}$;\5
\X626:Print the banner line, including the date and time\X;\6
$\\{input\_stack}[\\{input\_ptr}]\K\\{cur\_input}$;\C{make sure bottom level is
in memory}\6
$\\{print\_nl}(\.{"**"})$;\5
$\|l\K\\{input\_stack}[0].\\{limit\_field}-1$;\C{last position of first line}\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\6
\\{print\_ln};\C{now the transcript file contains the first line of input}\6
$\\{selector}\K\\{old\_setting}+2$;\C{\\{log\_only} or \\{term\_and\_log}}\6
\&{end};\par
\fi

\M625. Sometimes \\{open\_log\_file} is called at awkward moments when \MF\ is
unable to print error messages or even to \\{show\_context}.
Therefore the program is careful not to call \\{prompt\_file\_name} if a
fatal error could result.

Incidentally, the program always refers to the log file as a `\.{transcript
file}', because some systems cannot use the extension `\.{.log}' for
this file.

\Y\P$\4\X625:Try to get a different log file name\X\S$\6
\&{begin} \37\&{if} $\\{interaction}<\\{scroll\_mode}$ \1\&{then}\C{bypass %
\\{fatal\_error}}\6
\&{begin} \37$\\{print\_err}(\.{"I\ can\'t\ write\ on\ file\ \`"})$;\5
$\\{print\_file\_name}(\\{cur\_name},\39\\{cur\_area},\39\\{cur\_ext})$;\5
$\\{print}(\.{"\'."})$;\6
$\\{job\_name}\K0$;\5
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\6
\&{end};\C{abort the program without a log file}\2\6
$\\{prompt\_file\_name}(\.{"transcript\ file\ name"},\39\.{".log"})$;\6
\&{end}\par
\U section~624.\fi

\M626. \P$\X626:Print the banner line, including the date and time\X\S$\6
\&{begin} \37$\\{wlog}(\\{banner})$;\5
$\\{print}(\\{base\_ident})$;\5
$\\{print}(\.{"\ \ "})$;\5
$\\{print\_int}(\\{round\_unscaled}(\\{internal}[\\{day}]))$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{months}\K\.{\'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC\'}$;\5
$\|m\K\\{round\_unscaled}(\\{internal}[\\{month}])$;\6
\&{for} $\|k\K3\ast\|m-2\mathrel{\&{to}}3\ast\|m$ \1\&{do}\5
$\\{wlog}(\\{months}[\|k])$;\2\6
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\\{round\_unscaled}(\\{internal}[\\{year}]))$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\|m\K\\{round\_unscaled}(\\{internal}[\\{time}])$;\5
$\\{print\_dd}(\|m\mathbin{\&{div}}60)$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_dd}(\|m\mathbin{\&{mod}}60)$;\6
\&{end}\par
\U section~624.\fi

\M627. Let's turn now to the procedure that is used to initiate file reading
when an `\.{input}' command is being processed.

\Y\P\4\&{procedure}\1\  \37\\{start\_input};\C{\MF\ will \.{input} something}\6
\4\&{label} \37\\{done};\2\6
\&{begin} \37\\{scan\_file\_name};\C{set \\{cur\_name} to desired file name}\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\.{".mf"}$;\2\6
\\{pack\_cur\_name};\6
\~ \1\&{loop}\ \&{begin} \37\\{begin\_file\_reading};\C{set up \\{cur\_file}
and new level of input}\6
\&{if} $\\{a\_open\_in}(\\{cur\_file})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{pack\_file\_name}(\\{cur\_name},\39\\{MF\_area},\39\\{cur\_ext})$;\6
\&{if} $\\{a\_open\_in}(\\{cur\_file})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\\{end\_file\_reading};\C{remove the level that didn't work}\6
$\\{prompt\_file\_name}(\.{"input\ file\ name"},\39\.{".mf"})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{name}\K\\{a\_make\_name\_string}(\\{cur\_file})$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\6
\&{begin} \37$\\{job\_name}\K\\{cur\_name}$;\5
\\{open\_log\_file};\6
\&{end};\C{\\{open\_log\_file} doesn't \\{show\_context}, so \\{limit} 		and %
\\{loc} needn't be set to meaningful values yet}\2\6
\&{if} $\\{term\_offset}+\\{length}(\\{name})>\\{max\_print\_line}-2$ \1%
\&{then}\5
\\{print\_ln}\6
\4\&{else} \&{if} $(\\{term\_offset}>0)\V(\\{file\_offset}>0)$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\2\6
$\\{print\_char}(\.{"("})$;\5
$\\{print}(\\{name})$;\5
\\{update\_terminal};\5
$\\{state}\K\\{new\_line}$;\5
\X628:Read the first line of the new file\X;\6
\&{end};\par
\fi

\M628. Here we have to remember to tell the \\{input\_ln} routine not to
start with a \\{get}. If the file is empty, it is considered to
contain a single blank line.

\Y\P$\4\X628:Read the first line of the new file\X\S$\6
\&{begin} \37\&{if} $\R\\{input\_ln}(\\{cur\_file},\39\\{false})$ \1\&{then}\5
\\{do\_nothing};\2\6
\\{firm\_up\_the\_line};\5
$\\{buffer}[\\{limit}]\K\.{"\%"}$;\5
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\5
$\\{line}\K1$;\6
\&{end}\par
\U section~627.\fi

\N629.  \[xx] Font metric data.
\TeX\ gets its knowledge about fonts from font metric files, also called
\.{TFM} files; the `\.T' in `\.{TFM}' stands for \TeX,
but other programs know about them too. One of \MF's duties is to
write \.{TFM} files so that the user's fonts can readily be
applied to typesetting.

The information in a \.{TFM} file appears in a sequence of 8-bit bytes.
Since the number of bytes is always a multiple of~4, we could
also regard the file as a sequence of 32-bit words, but \MF\ uses the
byte interpretation. The format of \.{TFM} files was designed by
Lyle Ramshaw in 1980. The intent is to convey a lot of different kinds
of information in a compact but useful form.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{tfm\_file}: \37\\{byte\_file};\par
\fi

\M630. The first 24 bytes (6 words) of a \.{TFM} file contain twelve 16-bit
integers that give the lengths of the various subsequent portions
of the file. These twelve integers are, in order:
$$\vbox{\halign{\hfil#&$\null=\null$#\hfil\cr
\\{lf}&length of the entire file, in words;\cr
\\{lh}&length of the header data, in words;\cr
\\{bc}&smallest character code in the font;\cr
\\{ec}&largest character code in the font;\cr
\\{nw}&number of words in the width table;\cr
\\{nh}&number of words in the height table;\cr
\\{nd}&number of words in the depth table;\cr
\\{ni}&number of words in the italic correction table;\cr
\\{nl}&number of words in the lig/kern table;\cr
\\{nk}&number of words in the kern table;\cr
\\{ne}&number of words in the extensible character table;\cr
\\{np}&number of font parameter words.\cr}}$$
They are all nonnegative and less than $2↑{15}$. We must have $\\{bc}-1\L\\{ec}%
\L255$,
and
$$\hbox{$\\{lf}=6+\\{lh}+(\\{ec}-\\{bc}+1)+\\{nw}+\\{nh}+\\{nd}+\\{ni}+\\{nl}+%
\\{nk}+\\{ne}+\\{np}$.}$$
Note that a font may contain as many as 256 characters (if $\\{bc}=0$ and $%
\\{ec}=255$),
and as few as 0 characters (if $\\{bc}=\\{ec}+1$). An exception to these rules
is
planned for oriental fonts, which will be identified by the condition $%
\\{ec}=256$;
such fonts are not allowed except in extensions to \MF84.

Incidentally, when two or more 8-bit bytes are combined to form an integer of
16 or more bits, the most significant bytes appear first in the file.
This is called BigEndian order.

\fi

\M631. The rest of the \.{TFM} file may be regarded as a sequence of ten data
arrays having the informal specification
$$\def\arr$[#1]#2${\&{array} $[#1]$ \&{of} #2}
\vbox{\halign{\hfil\\{#}&$\,:\,$\arr#\hfil\cr
header&$[0\to\\{lh}-1]\hbox{\\{stuff}}$\cr
char\_info&$[\\{bc}\to\\{ec}]\\{char\_info\_word}$\cr
width&$[0\to\\{nw}-1]\\{fix\_word}$\cr
height&$[0\to\\{nh}-1]\\{fix\_word}$\cr
depth&$[0\to\\{nd}-1]\\{fix\_word}$\cr
italic&$[0\to\\{ni}-1]\\{fix\_word}$\cr
lig\_kern&$[0\to\\{nl}-1]\\{lig\_kern\_command}$\cr
kern&$[0\to\\{nk}-1]\\{fix\_word}$\cr
exten&$[0\to\\{ne}-1]\\{extensible\_recipe}$\cr
param&$[1\to\\{np}]\\{fix\_word}$\cr}}$$
The most important data type used here is a \\{fix\_word}, which is
a 32-bit representation of a binary fraction. A \\{fix\_word} is a signed
quantity, with the two's complement of the entire word used to represent
negation. Of the 32 bits in a \\{fix\_word}, exactly 12 are to the left of the
binary point; thus, the largest \\{fix\_word} value is $2048-2↑{-20}$, and
the smallest is $-2048$. We will see below, however, that all but two of
the \\{fix\_word} values must lie between $-16$ and $+16$.

\fi

\M632. The first data array is a block of header information, which contains
general facts about the font. The header must contain at least two words,
$\\{header}[0]$ and $\\{header}[1]$, whose meaning is explained below.
Additional header information of use to other software routines might
also be included, but \MF84 does not need to know about such details.
For example, 16 more words of header information are in use at the Xerox
Palo Alto Research Center; the first ten specify the character coding
scheme used (e.g., `\.{XEROX TEXT}' or `\.{TeX MATHSY}'), the next five
give the font family name (e.g., `\.{HELVETICA}' or `\.{CMSY}'), and the
last gives the ``face byte.''

\yskip\hang$\\{header}[0]$ is a 32-bit check sum that \MF\ will copy into
the \.{GF} output file. This helps ensure consistency between files,
since \TeX\ records the check sums from the \.{TFM}'s it reads, and these
should match the check sums on actual fonts that are used.  The actual
relation between this check sum and the rest of the \.{TFM} file is not
important; the check sum is simply an identification number with the
property that incompatible fonts almost always have distinct check sums.

\yskip\hang$\\{header}[1]$ is a \\{fix\_word} containing the design size of
the font, in units of \MF\ points. This number must be at least 1.0; it is
fairly arbitrary, but usually the design size is 10.0 for a ``10 point''
font, i.e., a font that was designed to look best at a 10-point size,
whatever that really means. When a \MF\ user asks for a font
`\.{at} $\delta$ \.{pt}', the effect is to override the design size
and replace it by $\delta$, and to multiply the $x$ and~$y$ coordinates
of the points in the font image by a factor of $\delta$ divided by the
design size.  {\sl All other dimensions in the\/ \.{TFM} file are
\\{fix\_word} numbers in design-size units.} Thus, for example, the value
of $\\{param}[6]$, which defines the \.{em} unit, is often the \\{fix\_word}
value
$2↑{20}=1.0$, since many fonts have a design size equal to one em.
The other dimensions must be less than 16 design-size units in absolute
value; thus, $\\{header}[1]$ and $\\{param}[1]$ are the only \\{fix\_word}
entries in the whole \.{TFM} file whose first byte might be something
besides 0 or 255.

\fi

\M633. Next comes the \\{char\_info} array, which contains one \\{char\_info%
\_word}
per character. Each word in this part of the file contains six fields
packed into four bytes as follows.

\yskip\hang first byte: \\{width\_index} (8 bits)\par
\hang second byte: \\{height\_index} (4 bits) times 16, plus \\{depth\_index}
(4~bits)\par
\hang third byte: \\{italic\_index} (6 bits) times 4, plus \\{tag}
(2~bits)\par
\hang fourth byte: \\{remainder} (8 bits)\par
\yskip\noindent
The actual width of a character is \\{width}$[\\{width\_index}]$, in
design-size
units; this is a device for compressing information, since many characters
have the same width. Since it is quite common for many characters
to have the same height, depth, or italic correction, the \.{TFM} format
imposes a limit of 16 different heights, 16 different depths, and
64 different italic corrections.

The italic correction of a character has two different uses.
(a)~In ordinary text, the italic correction is added to the width only if
the \TeX\ user specifies `\.{\\/}' after the character.
(b)~In math formulas, the italic correction is always added to the width,
unless the character has a subscript but no superscript.

Incidentally, the relation $\\{width}[0]=\\{height}[0]=\\{depth}[0]=
\\{italic}[0]=0$ should always hold, so that an index of zero implies a
value of zero.  The \\{width\_index} should never be zero unless the
character does not exist in the font, since a character is valid if and
only if it lies between \\{bc} and \\{ec} and has a nonzero \\{width\_index}.

\fi

\M634. The \\{tag} field in a \\{char\_info\_word} has four values that explain
how to
interpret the \\{remainder} field.

\yskip\hang$\\{tag}=0$ (\\{no\_tag}) means that \\{remainder} is unused.\par
\hang$\\{tag}=1$ (\\{lig\_tag}) means that this character has a
ligature/kerning
program starting at $\\{lig\_kern}[\\{remainder}]$.\par
\hang$\\{tag}=2$ (\\{list\_tag}) means that this character is part of a chain
of
characters of ascending sizes, and not the largest in the chain.  The
\\{remainder} field gives the character code of the next larger character.\par
\hang$\\{tag}=3$ (\\{ext\_tag}) means that this character code represents an
extensible character, i.e., a character that is built up of smaller pieces
so that it can be made arbitrarily large. The pieces are specified in
$\\{exten}[\\{remainder}]$.\par
\yskip\noindent
Characters with $\\{tag}=2$ and $\\{tag}=3$ are treated as characters with $%
\\{tag}=0$
unless they are used in special circumstances in math formulas. For example,
\TeX's \.{\\sum} operation looks for a \\{list\_tag}, and the \.{\\left}
operation looks for both \\{list\_tag} and \\{ext\_tag}.

\Y\P\D \37$\\{no\_tag}=0$\C{vanilla character}\par
\P\D \37$\\{lig\_tag}=1$\C{character has a ligature/kerning program}\par
\P\D \37$\\{list\_tag}=2$\C{character has a successor in a charlist}\par
\P\D \37$\\{ext\_tag}=3$\C{character is extensible}\par
\fi

\M635. The \\{lig\_kern} array contains instructions in a simple programming
language
that explains what to do for special letter pairs. Each word in this array is a
\\{lig\_kern\_command} of four bytes.

\yskip\hang first byte: \\{stop\_bit}, indicates the final program step
if the byte is 128 or more.\par
\hang second byte: \\{next\_char}, ``if \\{next\_char} follows the current
character,
then perform the operation and stop, otherwise continue.''\par
\hang third byte: \\{op\_bit}, indicates a ligature step if less than~128,
a kern step otherwise.\par
\hang fourth byte: \\{remainder}.\par
\yskip\noindent
In a ligature step the current character and \\{next\_char} are replaced by
the single character whose code is \\{remainder}. In a kern step, an
additional space equal to $\\{kern}[\\{remainder}]$ is inserted between the
current character and \\{next\_char}. (The value of $\\{kern}[\\{remainder}]$
is
often negative, so that the characters are brought closer together
by kerning, but it might be positive.)

\Y\P\D \37$\\{stop\_flag}=128+\\{min\_quarterword}$\C{value indicating `%
\.{STOP}' in a lig/kern program}\par
\P\D \37$\\{kern\_flag}=128+\\{min\_quarterword}$\C{op code for a kern step}\par
\P\D \37$\\{stop\_bit}(\#)\S\#.\\{b0}$\par
\P\D \37$\\{next\_char}(\#)\S\#.\\{b1}$\par
\P\D \37$\\{op\_bit}(\#)\S\#.\\{b2}$\par
\P\D \37$\\{rem\_byte}(\#)\S\#.\\{b3}$\par
\fi

\M636. Extensible characters are specified by an \\{extensible\_recipe}, which
consists of four bytes called \\{top}, \\{mid}, \\{bot}, and \\{rep} (in this
order). These bytes are the character codes of individual pieces used to
build up a large symbol.  If \\{top}, \\{mid}, or \\{bot} are zero, they are
not
present in the built-up result. For example, an extensible vertical line is
like an extensible bracket, except that the top and bottom pieces are missing.

Let $T$, $M$, $B$, and $R$ denote the respective pieces, or an empty box
if the piece isn't present. Then the extensible characters have the form
$TR↑kMR↑kB$ from top to bottom, for some $\|k\G0$, unless $M$ is absent;
in the latter case we can have $TR↑kB$ for both even and odd values of~\|k.
The width of the extensible character is the width of $R$; and the
height-plus-depth is the sum of the individual height-plus-depths of the
components used, since the pieces are butted together in a vertical list.

\Y\P\D \37$\\{ext\_top}(\#)\S\#.\\{b0}$\C{\\{top} piece in a recipe}\par
\P\D \37$\\{ext\_mid}(\#)\S\#.\\{b1}$\C{\\{mid} piece in a recipe}\par
\P\D \37$\\{ext\_bot}(\#)\S\#.\\{b2}$\C{\\{bot} piece in a recipe}\par
\P\D \37$\\{ext\_rep}(\#)\S\#.\\{b3}$\C{\\{rep} piece in a recipe}\par
\fi

\M637. The final portion of a \.{TFM} file is the \\{param} array, which is
another
sequence of \\{fix\_word} values.

\yskip\hang$\\{param}[1]=\\{slant}$ is the amount of italic slant, which is
used
to help position accents. For example, $\\{slant}=.25$ means that when you go
up one unit, you also go .25 units to the right. The \\{slant} is a pure
number; it is the only \\{fix\_word} other than the design size itself that is
not scaled by the design size.

\hang$\\{param}[2]=\\{space}$ is the normal spacing between words in text.
Note that character \O{40} in the font need not have anything to do with
blank spaces.

\hang$\\{param}[3]=\\{space\_stretch}$ is the amount of glue stretching between
words.

\hang$\\{param}[4]=\\{space\_shrink}$ is the amount of glue shrinking between
words.

\hang$\\{param}[5]=\\{x\_height}$ is the size of one ex in the font; it is also
the height of letters for which accents don't have to be raised or lowered.

\hang$\\{param}[6]=\\{quad}$ is the size of one em in the font.

\hang$\\{param}[7]=\\{extra\_space}$ is the amount added to $\\{param}[2]$ at
the
ends of sentences.

\yskip\noindent
If fewer than seven parameters are present, \MF\ sets the missing parameters
to zero. Fonts used for math symbols are required to have
additional parameter information, which is explained later.

\Y\P\D \37$\\{slant\_code}=1$\par
\P\D \37$\\{space\_code}=2$\par
\P\D \37$\\{space\_stretch\_code}=3$\par
\P\D \37$\\{space\_shrink\_code}=4$\par
\P\D \37$\\{x\_height\_code}=5$\par
\P\D \37$\\{quad\_code}=6$\par
\P\D \37$\\{extra\_space\_code}=7$\par
\fi

\M638. So that is what \.{TFM} files hold.

FIXTHIS to contain routines that output \.{TFM} files, as in \.{PLtoTF}.
\fi

\N639.  \[xx] Generic font file format.
The most important output produced by a production run of \MF\ is the
``generic font'' (\.{GF}) file that specifies the bit patterns of the
characters that have been constructed. The term {\sl generic\/} indicates that
this file format doesn't match the conventions of any name-brand manufacturer;
but it is easy to convert \.{GF} files to the special format required by
almost all digital phototypesetting equipment. There's a strong analogy
between the \.{DVI} files written by \TeX\ and the \.{GF} files written
by \MF; and, in fact, the file formats have a lot in common.

A \.{GF} file is a stream of 8-bit bytes that may be
regarded as a series of commands in a machine-like language. The first
byte of each command is the operation code, and this code is followed by
zero or more bytes that provide parameters to the command. The parameters
themselves may consist of several consecutive bytes; for example, the
`\\{boc}' (beginning of character) command has four parameters, each of
which is four bytes long. Parameters are usually regarded as nonnegative
integers; but four-byte-long parameters can be either positive or
negative, hence they range in value from $-2↑{31}$ to $2↑{31}-1$.

A \.{GF} file consists of a ``preamble,'' followed by a sequence of one or
more ``characters,'' followed by a ``postamble.'' The preamble is simply a
\\{pre} command, with its parameters that introduce the file; this must come
first.  Each ``character'' consists of a \\{boc} command, followed by any
number of other commands that specify the ``black'' pixels of a character,
followed by an \\{eoc} command. The characters appear in the order that \MF\
generated them. If we ignore no-op commands (which are allowed between any
two commands in the file), each \\{eoc} command is immediately followed by a
\\{boc} command, or by a \\{post} command; in the latter case, there are no
more characters in the file, and the remaining bytes form the postamble.
Further details about the postamble will be explained later.

Some parameters in \.{GF} commands are ``pointers.'' These are four-byte
quantities that give the location number of some other byte in the file;
the first byte is number~0, then comes number~1, and so on.

\fi

\M640. The \.{GF} format is intended to be both compact and easily interpreted
by a machine. Compactness is achieved by making most of the information
relative instead of absolute. When a \.{GF}-reading program reads the
commands for a character, it keeps track of several quantities: (a)~the current
row number,~\|y; (b)~the current column number,~\|x; and (c)~the current
starting-column number,~\|z. These are 32-bit signed integers, although
most actual font formats produced from \.{GF} files will need to curtail
this vast range because of practical limitations. (\MF\ output will never
allow $\vert x\vert$, $\vert y\vert$, or $\vert z\vert$ to exceed 4095,
but the \.{GF} format tries to be more general.)

How do \.{GF}'s row and column numbers correspond to the conventions
of \TeX\ and \MF? Well, the ``reference point'' of a character, in \TeX's
view, is considered to be at the lower left corner of the pixel in row~0
and column~0. This point is the intersection of the baseline with the left
edge of the type; it corresponds to location $(0,0)$ in \MF\ programs.
Thus the pixel in row~0 and column~0 is \MF's unit square, comprising the
region of the plane whose coordinates both lie between 0 and~1. Negative
values of~\|y correspond to rows of pixels {\sl below\/} the baseline.

Besides \|x, \|y, and \|z, there's also a fourth aspect of the current
state, namely the \\{paint\_switch}, which is always either \\{black} or
\\{white}. Each \\{paint} command advances \|x by a specified amount~\|d,
and blackens the intervening pixels if $\\{paint\_switch}=\\{black}$; then
the \\{paint\_switch} changes its state. \.{GF}'s commands are designed so
that \|x will never decrease within a row, and \|y will never increase
within a character; hence there is no way to whiten a pixel that has
been blackened.

\fi

\M641. Here is list of all the commands that may appear in a \.{GF} file. Each
command is specified by its symbolic name (e.g., \\{boc}), its opcode byte
(e.g., 67), and its parameters (if any). The parameters are followed
by a bracketed number telling how many bytes they occupy; for example,
`$\|d[2]$' means that parameter \|d is two bytes long.

\yskip\hang\\{paint\_0} 0. This is a \\{paint} command with $\|d=0$; it does
nothing but change the \\{paint\_switch} from \\{black} to \\{white} or
vice~versa.

\yskip\hang\\{paint\_1} through \\{paint\_63} (opcodes 1 to 63).
These are \\{paint} commands with $\|d=1$ to~63, defined as follows: If
$\\{paint\_switch}=\\{black}$, blacken \|d~pixels of the current row~\|y,
in columns \|x through $\|x+\|d-1$ inclusive. Then, in any case,
complement the \\{paint\_switch} and advance \|x by~\|d.

\yskip\hang\\{paint1} 64 $\|d[1]$. This is a \\{paint} command with a specified
value of~\|d; \MF uses it to paint when $64\L\|d<256$.

\yskip\hang\\{paint2} 65 $\|d[2]$. Same as \\{paint1}, but \|d~can be as high
as~65535.

\yskip\hang\\{paint3} 66 $\|d[3]$. Same as \\{paint1}, but \|d~can be as high
as $2↑{24}-1$. \MF\ never needs this command, and it is hard to imagine
anybody making practical use of it; surely a more compact encoding will be
desirable when characters can be this large. But the command is there,
anyway, just in case.

\yskip\hang\\{boc} 67 $\|c[4]$ $\|v[4]$ $\|y[4]$ $\|z[4]$. Beginning of a
character:
Here \|c is the character code; it is always in the range $0\L\|c<256$
for \MF\ output, but other codes are not illegal in general. The
``device width'' of this character is \|v; it is the value of \MF's
\&{chardw} parameter, rounded to the nearest integer, i.e., the number
of pixels that the font designer wishes the character to occupy when
it is typeset within a word. Finally, \|y~is the top row in which the
character might have black pixels, and \|z~is the leftmost potentially
black column in that row. These are the starting values of \|y and~\|z;
the current column number, \|x, is also initialized to equal~\|z.

\yskip\hang\\{eoc} 68. End of character: All pixels blackened so far
constitute the pattern for this character. In particular, a completely
blank character might have \\{eoc} immediately following \\{boc}.

\yskip\hang\\{skip1} 69 $\|m[1]$. Decrease \|y by $\|m+1$, set $\|x\K\|z$, and
set
$\\{paint\_switch}\K\\{black}$. This is a way to produce \|m all-white rows.

\yskip\hang\\{skip2} 70 $\|m[2]$. Same as \\{skip1}, but \|m can be as large
as 65535.

\yskip\hang\\{skip3} 71 $\|m[3]$. Same as \\{skip1}, but \|m can be as large
as $2↑{24}-1$. \MF\ obviously never needs this command.

\yskip\hang\\{new\_row} 72 $\|u[4]$. Decrease \|y by 1 and set $\|z\K\|z+\|u$;
then set
$\|x\K\|z$ and $\\{paint\_switch}\K\\{black}$. (It's a general way to finish
one row
and begin another.)

\yskip\hang\\{left\_z\_82} through \\{left\_z\_1} (opcodes 73 to 154). Same as
\\{new\_row}, with $\|u=-82$ through $-1$, respectively.

\yskip\hang\\{right\_z\_0} 155. Same as \\{skip1} with $\|m=0$ or \\{new\_row}
with
$\|u=0$.

\yskip\hang\\{right\_z\_1} through \\{right\_z\_82} (opcodes 156 to 237). Same
as
\\{new\_row}, with $\|u=+1$ through $+82$, respectively. \MF\ generates a
\\{new\_row} command only when $\vert u\vert>82$.

\yskip\hang\\{nop} 238. No operation, do nothing. Any number of \\{nop}'s
may occur between \.{GF} commands, but a \\{nop} cannot be inserted between
a command and its parameters or between two parameters.

\yskip\hang\\{xxx1} 239 $\|k[1]$ $\|x[\|k]$ $\|v[4]$. This command is undefined
in
general; it functions as a $(k+6)$-byte \\{nop} unless special \.{GF}-reading
programs are being used. \MF\ generates \\{xxx} commands when encountering
a \&{special} string; this occurs in the \.{GF} file only between
characters, after the preamble, and before the postamble. However, \\{xxx}
commands can appear anywhere. It is recommended that \|x be a string
having the form of a keyword followed by possible parameters relevant to
that keyword. There's also a 4-byte numeric parameter that comes with the
command; \MF\ puts a \\{scaled} integer there.

\yskip\hang\\{xxx2} 240 $\|k[2]$ $\|x[\|k]$ $\|v[4]$. Like \\{xxx1}, but $0\L%
\|k<65536$.

\yskip\hang\\{xxx3} 241 $\|k[3]$ $\|x[\|k]$ $\|v[4]$. Like \\{xxx1}, but
$0\L\|k<\hbox{$2↑{24}$}$.  \MF\ uses this when sending a \&{special} string
whose length exceeds~255.

\yskip\hang\\{xxx4} 242 $\|k[4]$ $\|x[\|k]$ $\|v[4]$. Like \\{xxx1}, but \|k
can be
ridiculously large; \|k mustn't be negative.

\yskip\hang\\{char\_loc1} 243 $\|c[1]$ $\|w[4]$ $\|p[4]$.
This command will appear only in the postamble, which will be explained
shortly.

\yskip\hang\\{char\_loc2} 244 $\|c[2]$ $\|w[4]$ $\|p[4]$.
Like \\{char\_loc1}, but $0\L\|c<65536$.

\yskip\hang\\{char\_loc3} 245 $\|c[3]$ $\|w[4]$ $\|p[4]$.
Like \\{char\_loc1}, but $0\L\|c<\hbox{$2↑{24}$}$.

\yskip\hang\\{char\_loc4} 246 $\|c[4]$ $\|w[4]$ $\|p[4]$.
Like \\{char\_loc1}, but $\hbox{$-2↑{31}$}\L\|c<\hbox{$2↑{31}$}$.

\yskip\hang\\{pre} 247 $\|i[1]$ $\|k[1]$ $\|x[\|k]$.
Beginning of the preamble; this must come at the very beginning of the
file. Parameter \|i is an identifying number for \.{GF} format, currently
129. The other information is merely commentary; it is not given
special interpretation like \\{xxx} commands are. (Note that \\{xxx}
commands may immediately follow the preamble, before the first \\{boc}.)

\yskip\hang\\{post} 248. Beginning of the postamble, see below.

\yskip\hang\\{post\_post} 249. Ending of the postamble, see below.

\yskip\noindent Commands 250--255 are undefined at the present time.

\Y\P\D \37$\\{gf\_id\_byte}=129$\C{identifies the kind of \.{GF} files
described here}\par
\fi

\M642. Here are the opcodes \MF\ actually refers to.

\Y\P\D \37$\\{paint\_0}=0$\C{beginning of the \\{paint} commands}\par
\P\D \37$\\{paint1}=64$\C{move right a given number of columns, then 	black${}%
\swap{}$white}\par
\P\D \37$\\{boc}=67$\C{beginning of a character}\par
\P\D \37$\\{eoc}=68$\C{end of a character}\par
\P\D \37$\\{skip1}=69$\C{skip over blank rows}\par
\P\D \37$\\{new\_row}=72$\C{move down one row and adjust \|z}\par
\P\D \37$\\{right\_z\_0}=155$\C{base of shorthand \\{new\_row} commands}\par
\P\D \37$\\{xxx1}=239$\C{for \&{special} strings}\par
\P\D \37$\\{xxx3}=241$\C{for long \&{special} strings}\par
\P\D \37$\\{char\_loc1}=243$\C{character locators in the postamble}\par
\P\D \37$\\{pre}=247$\C{preamble}\par
\P\D \37$\\{post}=248$\C{postamble beginning}\par
\P\D \37$\\{post\_post}=249$\C{postamble ending}\par
\fi

\M643. The last character in a \.{GF} file is followed by `\\{post}'; this
command
introduces the postamble, which summarizes important facts that \MF\ has
accumulated. The postamble has the form
$$\vbox{\halign{\hbox{#\hfil}\cr
\\{post} $\|p[4]$ $\\{ds}[4]$ $\\{cs}[4]$ $\\{ppp}[4]$
$\\{minx}[4]$ $\\{maxx}[4]$ $\\{miny}[4]$ $\\{maxy}[4]$\cr
$\langle\,$character locations$\,\rangle$\cr
\\{post\_post} $\|q[4]$ $\|i[1]$ 223's$[{\G}4]$\cr}}$$
Here \|p is a pointer to the byte following the final \\{eoc} in the file
(or to the byte following the preamble, if there are no characters);
it can be used to locate the beginning of \\{xxx} commands
that might have preceded the postamble. The \\{ds} and \\{cs} parameters
give the design size and check sum, respectively, which are exactly the
values put into the header of the \.{TFM} file that \MF\ produces (or
would produce) on this run. Parameter \\{ppp} is the number of pixels
per point, expressed as a \\{scaled} integer (i.e., multiplied by
$2↑{16}$); this can be used to correlate the font with specific
device resolutions, magnifications, and ``at sizes.''  Then come \\{minx},
\\{maxx}, \\{miny}, and \\{maxy}, which bound the values that \|x and~\|y
assume
in all of the characters of this \.{GF} file.

Character locators are introduced by \\{char\_loc} commands (opcodes 243--246),
which contain a character number~\|c, a character width~\|w, and a pointer~\|p
to the beginning of that character. (If two or more characters have the
same code~\|c, only the last will be indicated.) The character width~\|w
duplicates the information in the \.{TFM} file; it is a \\{fix\_word} value
relative to the design size, and it should be independent of magnification.
The pointer \|p points to the character's \\{boc}, or to \\{xxx} or \\{nop}
commands that precede the \\{boc}, if such commands exist; such ``special''
commands essentially belong to the characters, while the special commands
after the final character belong to the postamble (i.e., to the font
as a whole).

\fi

\M644. The last part of the postamble, following the \\{post\_post} byte that
signifies the end of the character locators, contains \|q, a pointer to the
\\{post} command that started the postamble.  An identification byte, \|i,
comes next; this currently equals~129, as in the preamble.

The \|i byte is followed by four or more bytes that are all equal to
the decimal number 223 (i.e., \O{337} in octal). \MF\ puts out four to seven of
these trailing bytes, until the total length of the file is a multiple of
four bytes, since this works out best on machines that pack four bytes per
word; but any number of 223's is allowed, as long as there are at least four
of them. In effect, 223 is a sort of signature that is added at the very end.

This curious way to finish off a \.{GF} file makes it feasible for
\.{GF}-reading programs to find the postamble first, on most computers,
even though \MF\ wants to write the postamble last. Most operating
systems permit random access to individual words or bytes of a file, so
the \.{GF} reader can start at the end and skip backwards over the 223's
until finding the identification byte. Then it can back up four bytes, read
\|q, and move to byte \|q of the file. This byte should, of course,
contain the value 248 (\\{post}); now the postamble can be read, so the
\.{GF} reader discovers all the information needed for individual characters.

Unfortunately, however, standard \PASCAL\ does not include the ability to
access a random position in a file, or even to determine the length of a file.
Almost all systems nowadays provide the necessary capabilities, so \.{GF}
format has been designed to work most efficiently with modern operating
systems.
But if \.{GF} files have to be processed under the restrictions of standard
\PASCAL, one can simply read them from front to back. This will
be adequate for most applications. However, the postamble-first approach
would facilitate a program that merges two \.{GF} files, replacing data
from one that is overridden by corresponding data in the other.
\fi

\N645.  \[xx] Shipping characters out.
The \\{ship\_out} procedure, to be described below, is given a pointer to
an edge structure. Its mission is to describe the the positive pixels
in \.{GF} form, outputting a ``character'' to \\{gf\_file}.

Sevel global variables maintain information about the font file as a whole:
\\{gf\_min\_x}, \\{gf\_max\_x}, \\{gf\_min\_y}, and \\{gf\_max\_y} are the
minimum and
maximum pixel coordinates output so far; \\{gf\_prev\_ptr} is the byte number
following the preamble or the last \\{eoc} command in the output;
\\{total\_chars} is the total number of characters shipped out.
There's also an array, \\{char\_ptr}, containing the starting positions
of each character in the file, as required for the postamble. If
character code~\|c has not yet been output, $\\{char\_ptr}[\|c]=-1$.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{gf\_min\_x},\39\\{gf\_max\_x},\39\\{gf\_min\_y},\39\\{gf\_max\_y}$: \37%
\\{integer};\C{bounding rectangle}\6
\4\\{gf\_prev\_ptr}: \37\\{integer};\C{where the present/next character
started/starts}\6
\4\\{total\_chars}: \37\\{integer};\C{the number of characters output so far}\6
\4\\{char\_ptr}: \37\&{array} $[\\{eight\_bits}]$ \1\&{of}\5
\\{integer};\C{where individual characters started}\2\par
\fi

\M646. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{gf\_prev\_ptr}\K0$;\5
$\\{total\_chars}\K0$;\par
\fi

\M647. The \.{GF} bytes are output to a buffer instead of being sent
byte-by-byte to \\{gf\_file}, because this tends to save a lot of
subroutine-call overhead. \MF\ uses the same conventions for \\{gf\_file}
as \TeX\ uses for its \\{dvi\_file}; hence if system-dependent
changes are needed, they are the same for both programs.

The output buffer is divided into two parts of equal size; the bytes found
in $\\{gf\_buf}[0\to\\{half\_buf}-1]$ constitute the first half, and those in
$\\{gf\_buf}[\\{half\_buf}\to\\{gf\_buf\_size}-1]$ constitute the second. The
global
variable \\{gf\_ptr} points to the position that will receive the next
output byte. When \\{gf\_ptr} reaches \\{gf\_limit}, which is always equal
to one of the two values \\{half\_buf} or \\{gf\_buf\_size}, the half buffer
that
is about to be invaded next is sent to the output and \\{gf\_limit} is
changed to its other value. Thus, there is always at least a half buffer's
worth of information present, except at the very beginning of the job.

Bytes of the \.{GF} file are numbered sequentially starting with 0;
the next byte to be generated will be number $\\{gf\_offset}+\\{gf\_ptr}$.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{gf\_index}=0\to\\{gf\_buf\_size}$;\C{an index into the output buffer}\par
\fi

\M648. Some systems may find it more efficient to make \\{gf\_buf} a \&{packed}
array, since output of four bytes at once may be facilitated.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{gf\_buf}: \37\&{array} $[\\{gf\_index}]$ \1\&{of}\5
\\{eight\_bits};\C{buffer for \.{GF} output}\2\6
\4\\{half\_buf}: \37\\{gf\_index};\C{half of \\{gf\_buf\_size}}\6
\4\\{gf\_limit}: \37\\{gf\_index};\C{end of the current half buffer}\6
\4\\{gf\_ptr}: \37\\{gf\_index};\C{the next available buffer address}\6
\4\\{gf\_offset}: \37\\{integer};\C{\\{gf\_buf\_size} times the number of times
the 	output buffer has been fully emptied}\par
\fi

\M649. Initially the buffer is all in one piece; we will output half of it only
after it first fills up.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{half\_buf}\K\\{gf\_buf\_size}\mathbin{\&{div}}2$;\5
$\\{gf\_limit}\K\\{gf\_buf\_size}$;\5
$\\{gf\_ptr}\K0$;\5
$\\{gf\_offset}\K0$;\par
\fi

\M650. The actual output of $\\{gf\_buf}[\|a\to\|b]$ to \\{gf\_file} is
performed by calling
$\\{write\_gf}(\|a,\|b)$. For best results, this procedure should be optimized
to
run as fast as possible on each particular system, since it is part of
\TeX's inner loop. It is safe to assume that \|a and $\|b+1$ will both be
multiples of 4 when $\\{write\_gf}(\|a,\|b)$ is called; therefore it is
possible on
many machines to use efficient methods to pack four bytes per word and to
output an array of words with one system call.

\Y\P\4\&{procedure}\1\  \37$\\{write\_gf}(\|a,\39\|b:\\{gf\_index})$;\6
\4\&{var} \37\|k: \37\\{gf\_index};\2\6
\&{begin} \37\&{for} $\|k\K\|a\mathrel{\&{to}}\|b$ \1\&{do}\5
$\\{write}(\\{gf\_file},\39\\{gf\_buf}[\|k])$;\2\6
\&{end};\par
\fi

\M651. To put a byte in the buffer without paying the cost of invoking a
procedure
each time, we use the macro \\{gf\_out}.

\Y\P\D \37$\\{gf\_out}(\#)\S$\ \&{begin} \37$\\{gf\_buf}[\\{gf\_ptr}]\K\#$;\5
$\\{incr}(\\{gf\_ptr})$;\6
\&{if} $\\{gf\_ptr}=\\{gf\_limit}$ \1\&{then}\5
\\{gf\_swap};\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37\\{gf\_swap};\C{outputs half of the buffer}\2\6
\&{begin} \37\&{if} $\\{gf\_limit}=\\{gf\_buf\_size}$ \1\&{then}\6
\&{begin} \37$\\{write\_gf}(0,\39\\{half\_buf}-1)$;\5
$\\{gf\_limit}\K\\{half\_buf}$;\5
$\\{gf\_offset}\K\\{gf\_offset}+\\{gf\_buf\_size}$;\5
$\\{gf\_ptr}\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{write\_gf}(\\{half\_buf},\39\\{gf\_buf\_size}-1)$;\5
$\\{gf\_limit}\K\\{gf\_buf\_size}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M652. Here is how we clean out the buffer when \TeX\ is all through; \\{gf%
\_ptr}
will be a multiple of~4.

\Y\P$\4\X652:Empty the last bytes out of \\{gf\_buf}\X\S$\6
\&{if} $\\{gf\_limit}=\\{half\_buf}$ \1\&{then}\5
$\\{write\_gf}(\\{half\_buf},\39\\{gf\_buf\_size}-1)$;\2\6
\&{if} $\\{gf\_ptr}>0$ \1\&{then}\5
$\\{write\_gf}(0,\39\\{gf\_ptr}-1)$\2\par
\U section~665.\fi

\M653. The \\{gf\_four} procedure outputs four bytes in two's complement
notation,
without risking arithmetic overflow.

\Y\P\4\&{procedure}\1\  \37$\\{gf\_four}(\|x:\\{integer})$;\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{gf\_out}(\|x\mathbin{\&{div}}\O{100000000})$\6
\4\&{else} \&{begin} \37$\|x\K\|x+\O{10000000000}$;\5
$\|x\K\|x+\O{10000000000}$;\5
$\\{gf\_out}((\|x\mathbin{\&{div}}\O{100000000})+128)$;\6
\&{end};\2\6
$\|x\K\|x\mathbin{\&{mod}}\O{100000000}$;\5
$\\{gf\_out}(\|x\mathbin{\&{div}}\O{200000})$;\5
$\|x\K\|x\mathbin{\&{mod}}\O{200000}$;\5
$\\{gf\_out}(\|x\mathbin{\&{div}}\O{400})$;\5
$\\{gf\_out}(\|x\mathbin{\&{mod}}\O{400})$;\6
\&{end};\par
\fi

\M654. Of course, it's even easier to output just two or three bytes.

\Y\P\4\&{procedure}\1\  \37$\\{gf\_two}(\|x:\\{integer})$;\2\6
\&{begin} \37$\\{gf\_out}(\|x\mathbin{\&{div}}\O{400})$;\5
$\\{gf\_out}(\|x\mathbin{\&{mod}}\O{400})$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{gf\_three}(\|x:\\{integer})$;\2\6
\&{begin} \37$\\{gf\_out}(\|x\mathbin{\&{div}}\\{unity})$;\5
$\\{gf\_out}((\|x\mathbin{\&{mod}}\\{unity})\mathbin{\&{div}}\O{400})$;\5
$\\{gf\_out}(\|x\mathbin{\&{mod}}\O{400})$;\6
\&{end};\par
\fi

\M655. We need two simple routines to generate a \\{paint} or \\{new\_row}
command of the appropriate type.

\Y\P\4\&{procedure}\1\  \37$\\{gf\_paint}(\|d:\\{integer})$;\C{assumes that $%
\|d<65536$}\2\6
\&{begin} \37\&{if} $\|d<64$ \1\&{then}\5
$\\{gf\_out}(\\{paint\_0}+\|d)$\6
\4\&{else} \&{if} $\|d<256$ \1\&{then}\6
\&{begin} \37$\\{gf\_out}(\\{paint1})$;\5
$\\{gf\_out}(\|d)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{gf\_out}(\\{paint1}+1)$;\5
$\\{gf\_two}(\|d)$;\6
\&{end};\2\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{gf\_new\_row}(\|d:\\{integer})$;\2\6
\&{begin} \37\&{if} $\\{abs}(\|d)\L82$ \1\&{then}\5
$\\{gf\_out}(\\{right\_z\_0}+\|d)$\6
\4\&{else} \&{begin} \37$\\{gf\_out}(\\{new\_row})$;\5
$\\{gf\_four}(\|d)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M656. And \\{gf\_string} outputs a string.

\Y\P\4\&{procedure}\1\  \37$\\{gf\_string}(\|s:\\{str\_number})$;\6
\4\&{var} \37\|k: \37\\{pool\_pointer};\2\6
\&{begin} \37\&{for} $\|k\K\\{str\_start}[\|s]\mathrel{\&{to}}\\{str\_start}[%
\|s+1]-1$ \1\&{do}\5
$\\{gf\_out}(\\{str\_pool}[\|k])$;\2\6
\&{end};\par
\fi

\M657. Here is a routine that gets a \.{GF} file off to a good start.

\Y\P\D \37$\\{check\_gf}\S$\1\6
\&{if} $\\{total\_chars}=0$ \1\&{then}\5
\\{init\_gf}\2\2\par
\Y\P\4\&{procedure}\1\  \37\\{init\_gf};\6
\4\&{var} \37\|k: \37\\{eight\_bits};\C{runs through all possible character
codes}\6
\|t: \37\\{integer};\C{the time of this run}\2\6
\&{begin} \37$\\{gf\_min\_x}\K4096$;\5
$\\{gf\_max\_x}\K-4095$;\5
$\\{gf\_min\_y}\K4096$;\5
$\\{gf\_max\_y}\K-4096$;\6
\&{for} $\|k\K0\mathrel{\&{to}}255$ \1\&{do}\5
$\\{char\_ptr}[\|k]\K-1$;\2\6
\\{ensure\_gf\_open};\5
$\\{gf\_out}(\\{pre})$;\5
$\\{gf\_out}(\\{gf\_id\_byte})$;\C{begin to output the preamble}\6
$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{print}(\.{"\ METAFONT\ output\ "})$;\5
$\\{print\_int}(\\{round\_unscaled}(\\{internal}[\\{year}]))$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_dd}(\\{round\_unscaled}(\\{internal}[\\{month}]))$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_dd}(\\{round\_unscaled}(\\{internal}[\\{day}]))$;\5
$\\{print\_char}(\.{":"})$;\6
$\|t\K\\{round\_unscaled}(\\{internal}[\\{time}])$;\5
$\\{print\_dd}(\|t\mathbin{\&{div}}60)$;\5
$\\{print\_dd}(\|t\mathbin{\&{mod}}60)$;\6
$\\{selector}\K\\{old\_setting}$;\5
$\\{gf\_out}(\\{cur\_length})$;\5
$\\{str\_start}[\\{str\_ptr}+1]\K\\{pool\_ptr}$;\5
$\\{gf\_string}(\\{str\_ptr})$;\5
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\C{flush that string from memory}%
\6
$\\{gf\_prev\_ptr}\K\\{gf\_ptr}$;\6
\&{end};\par
\fi

\M658. With those preliminaries out of the way, \\{ship\_out} is not especially
difficult.

\Y\P\4\&{procedure}\1\  \37$\\{ship\_out}(\|h:\\{pointer})$;\6
\4\&{var} \37\|c: \37\\{integer};\C{the character code}\6
$\\{prev\_m},\39\|m$: \37\\{integer};\C{previous and current pixel column
numbers}\6
$\\{prev\_n},\39\|n$: \37\\{integer};\C{previous and current pixel row numbers}%
\6
$\|p,\39\|q$: \37\\{pointer};\C{for list traversal}\6
$\|w,\39\\{ww}$: \37\\{integer};\C{old and new weights}\6
\|d: \37\\{integer};\C{data from edge-weight node}\6
\\{delta}: \37\\{integer};\C{number of rows to skip}\6
\|z: \37\\{integer};\C{starting column}\2\6
\&{begin} \37$\|c\K\\{round\_unscaled}(\\{internal}[\\{char\_code}])$;\6
\&{if} $(\|c<0)\V(\|c>255)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ character\ code\ ("})$;\5
$\\{print\_int}(\|c)$;\5
$\\{print\_char}(\.{")"})$;\5
$\\{help2}(\.{"A\ charcode\ should\ be\ between\ 0\ and\ 255."})$\6
$(\.{"I\'ve\ set\ this\ to\ zero."})$;\5
$\|c\K0$;\5
$\\{value}(\\{char\_code})\K0$;\5
\\{error};\6
\&{end};\2\6
$\\{char\_ptr}[\|c]\K\\{gf\_prev\_ptr}$;\5
$\\{gf\_out}(\\{boc})$;\5
$\\{gf\_four}(\|c)$;\5
$\\{gf\_four}(\\{round\_unscaled}(\\{internal}[\\{char\_dw}]))$;\5
\X659:Output the character represented in \|h\X;\6
$\\{gf\_out}(\\{eoc})$;\5
$\\{gf\_prev\_ptr}\K\\{gf\_offset}+\\{gf\_ptr}$;\5
$\\{incr}(\\{total\_chars})$;\6
\&{end};\par
\fi

\M659. \P$\X659:Output the character represented in \|h\X\S$\6
$\\{prev\_n}\K4096$;\5
$\|p\K\\{knil}(\|h)$;\5
$\|n\K\\{n\_max}(\|h)-\\{zero\_field}$;\6
\&{while} $\|p\I\|h$ \1\&{do}\6
\&{begin} \37\X660:Output the pixels of edge row \|p to font row \|n\X;\6
$\|p\K\\{knil}(\|p)$;\5
$\\{decr}(\|n)$;\6
\&{end};\2\6
\&{if} $\\{prev\_n}=4096$ \1\&{then}\C{character was entirely blank}\6
\&{begin} \37$\\{gf\_four}(0)$;\5
$\\{gf\_four}(0)$;\C{complete the \\{boc} command}\6
\&{end}\6
\4\&{else} \&{if} $\\{prev\_n}<\\{gf\_y\_min}$ \1\&{then}\5
$\\{gf\_y\_min}\K\\{prev\_n}$\2\2\par
\U section~658.\fi

\M660. \P$\X660:Output the pixels of edge row \|p to font row \|n\X\S$\6
\&{if} $\\{unsorted}(\|p)>\\{null1}$ \1\&{then}\5
$\\{sort\_edges}(\|p)$;\2\6
$\|q\K\\{sorted}(\|p)$;\5
$\|w\K0$;\5
$\\{prev\_m}\K-\\{fraction\_one}$;\C{$-\\{fraction\_one}\approx\infty$}\6
\&{while} $\|q>\\{sentinel}$ \1\&{do}\6
\&{begin} \37$\|d\K\\{ho}(\\{info}(\|q))$;\5
$\|m\K\|d\mathbin{\&{div}}8$;\5
$\\{ww}\K\|w+(\|d\mathbin{\&{mod}}8)-\\{zero\_w}$;\6
\&{if} $\|w\L0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{ww}>0$ \1\&{then}\6
\&{if} $\|m>\\{prev\_m}$ \1\&{then}\5
\X661:Start black at $(m,n)$\X;\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{ww}\L0$ \1\&{then}\6
\&{if} $\|m>\\{prev\_m}$ \1\&{then}\5
\X662:Stop black at $(m,n)$\X;\2\2\2\6
$\|w\K\\{ww}$;\5
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\&{if} $\|w\I0$ \1\&{then}\5
$\\{confusion}(\.{"pixels"})$;\2\6
\&{if} $\\{prev\_m}-\\{m\_offset}(\|h)>\\{gf\_x\_max}$ \1\&{then}\5
$\\{gf\_x\_max}\K\\{prev\_m}-\\{m\_offset}(\|h)$\2\par
\U section~659.\fi

\M661. \P$\X661:Start black at $(m,n)$\X\S$\6
\&{begin} \37\&{if} $\\{prev\_m}=-\\{fraction\_one}$ \1\&{then}\5
\X663:Start a new row at $(m,n)$\X\6
\4\&{else} $\\{gf\_paint}(\|m-\\{prev\_m})$;\2\6
$\\{prev\_m}\K\|m$;\6
\&{end}\par
\U section~660.\fi

\M662. \P$\X662:Stop black at $(m,n)$\X\S$\6
\&{begin} \37$\\{gf\_paint}(\|m-\\{prev\_m})$;\5
$\\{prev\_m}\K\|m$;\6
\&{end}\par
\U section~660.\fi

\M663. \P$\X663:Start a new row at $(m,n)$\X\S$\6
\&{begin} \37$\\{mm}\K\|m-\\{m\_offset}(\|h)$;\6
\&{if} $\\{mm}<\\{gf\_x\_min}$ \1\&{then}\5
$\\{gf\_x\_min}\K\\{mm}$;\2\6
\&{if} $\\{prev\_n}=4096$ \1\&{then}\6
\&{begin} \37\&{if} $\|n>\\{gf\_y\_max}$ \1\&{then}\5
$\\{gf\_y\_max}\K\|n$;\2\6
$\\{gf\_four}(\|n)$;\5
$\\{gf\_four}(\\{mm})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{prev\_n}>\|n+1$ \1\&{then}\5
\X664:Skip to $(m,n)$\X\6
\4\&{else} $\\{gf\_new\_row}(\|z-\|m)$;\2\2\6
$\|z\K\|m$\par
\U section~661.\fi

\M664. \P$\X664:Skip to $(m,n)$\X\S$\6
\&{begin} \37$\\{delta}\K\\{prev\_n}-\|n-1$;\6
\&{if} $\|m\I\|z$ \1\&{then}\6
\&{begin} \37$\\{gf\_new\_row}(\|z-\|m)$;\5
$\\{decr}(\\{delta})$;\6
\&{end};\2\6
\&{if} $\\{delta}<\O{400}$ \1\&{then}\6
\&{begin} \37$\\{gf\_out}(\\{skip1})$;\5
$\\{gf\_out}(\\{delta})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{gf\_out}(\\{skip2})$;\5
$\\{gf\_two}(\\{delta})$;\6
\&{end};\2\6
\&{end}\par
\U section~663.\fi

\M665. At the end of the program we must finish things off by writing the
postamble.
The \.{TFM} information should have been computed first.

An integer variable \|k will be declared for use by this routine.

\Y\P$\4\X665:Finish the \.{GF} file\X\S$\6
\&{if} $\\{gf\_prev\_ptr}>0$ \1\&{then}\6
\&{begin} \37$\\{gf\_out}(\\{post})$;\C{beginning of the postamble}\6
$\\{gf\_four}(\\{gf\_prev\_ptr})$;\5
$\\{gf\_prev\_ptr}\K\\{gf\_offset}+\\{gf\_ptr}-5$;\C{\\{post} location}\6
$\\{gf\_four}(\\{internal}[\\{design\_size}]\ast16)$;\5
$\\{gf\_four}(\\{check\_sum})$;\5
$\\{gf\_four}(\\{internal}[\\{ppp}])$;\5
$\\{gf\_four}(\\{gf\_min\_x})$;\5
$\\{gf\_four}(\\{gf\_max\_x}-1)$;\5
$\\{gf\_four}(\\{gf\_min\_y})$;\5
$\\{gf\_four}(\\{gf\_max\_y})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}255$ \1\&{do}\6
\&{if} $\\{char\_ptr}[\|k]\G0$ \1\&{then}\6
\&{begin} \37$\\{gf\_out}(\\{char\_loc1})$;\5
$\\{gf\_out}(\|k)$;\5
$\\{gf\_four}(\\{tfm\_width}[\|k])$;\5
$\\{gf\_four}(\\{char\_ptr}[\|k])$;\6
\&{end};\2\2\6
$\\{gf\_out}(\\{post\_post})$;\5
$\\{gf\_four}(\\{gf\_prev\_ptr})$;\5
$\\{gf\_out}(\\{gf\_id\_byte})$;\6
$\|k\K4+((\\{gf\_buf\_size}-\\{gf\_ptr})\mathbin{\&{mod}}4)$;\C{the number of
223's}\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{gf\_out}(223)$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
\X652:Empty the last bytes out of \\{gf\_buf}\X;\6
$\\{print\_nl}(\.{"Output\ written\ on\ "})$;\5
$\\{print}(\\{output\_file\_name})$;\5
$\\{print}(\.{"\ ("})$;\5
$\\{print\_int}(\\{total\_chars})$;\5
$\\{print}(\.{"\ character"})$;\6
\&{if} $\\{total\_chars}\I0$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$;\2\6
$\\{print}(\.{",\ "})$;\5
$\\{print\_int}(\\{gf\_offset}+\\{gf\_ptr})$;\5
$\\{print}(\.{"\ bytes)."})$;\5
$\\{b\_close}(\\{gf\_file})$;\6
\&{end}\2\par
\U section~812.\fi

\N666.  \[xx] Introduction to the parsing routines.
We come now to the central nervous system that sparks many of \MF's activities.
By evaluating expressions, from their primary constituents to ever larger
subexpressions, \MF\ builds the structures that ultimately define fonts.

Four mutually recursive subroutines are involved in this process: We call them
\\{scan\_primary}, \\{scan\_secondary}, \\{scan\_tertiary}, and \\{scan%
\_expression}.
Each of them is parameterless and begins with the first token to be scanned
already represented in \\{cur\_cmd}, \\{cur\_mod}, and \\{cur\_sym}. After
execution,
the value of the primary or secondary or tertiary or expression that was
found will appear in the global variables \\{cur\_type} and \\{cur\_exp}. The
token following the expression wil be represented in \\{cur\_cmd}, \\{cur%
\_mod},
and \\{cur\_sym}.

Technically speaking, the parsing algorithms are ``LL(1),'' more or less;
backup mechanisms have been added in order to provide reasonable error
recovery.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_type}: \37\\{small\_number};\C{the type of the expression just found}%
\6
\4\\{cur\_exp}: \37\\{integer};\C{the value of the expression just found}\par
\fi

\M667. Many different kinds of expressions are possible, so it is wise to have
precise descriptions of what \\{cur\_type} and \\{cur\_exp} mean in all cases:

\smallskip\hang
$\\{cur\_type}=\\{vacuous}$ means that this expression didn't turn out to have
a
value at all, because it arose from a \&{begingroup}$\,\ldots\,$\&{endgroup}
construction in which there was no expression before the \&{endgroup}.
In this case \\{cur\_exp} has some irrelevant value.

\smallskip\hang
$\\{cur\_type}=\\{boolean\_type}$ means that \\{cur\_exp} is either \\{true%
\_code}
or \\{false\_code}.

\smallskip\hang
$\\{cur\_type}=\\{unknown\_boolean}$ means that \\{cur\_exp} points to a
capsule
node that is either \\{boolean\_type} or in the ring of variables equivalent
to at least one undefined boolean variable.

\smallskip\hang
$\\{cur\_type}=\\{string\_type}$ means that \\{cur\_exp} is a string number
(i.e., an
integer in the range $0\L\\{cur\_exp}<\\{str\_ptr}$).

\smallskip\hang
$\\{cur\_type}=\\{unknown\_string}$ means that \\{cur\_exp} points to a capsule
node that is either \\{string\_type} or in the ring of variables equivalent
to at least one undefined string variable.

\smallskip\hang
$\\{cur\_type}=\\{pen\_type}$ means that \\{cur\_exp} points to a pen header
node. This
node contains a reference count, which takes account of this particular
reference.

\smallskip\hang
$\\{cur\_type}=\\{unknown\_pen}$ means that \\{cur\_exp} points to a capsule
node that is either \\{pen\_type} or in the ring of variables equivalent
to at least one undefined pen variable.

\smallskip\hang
$\\{cur\_type}=\\{future\_pen}$ means that \\{cur\_exp} points to a knot list
that
should eventually be made into a pen. Nobody else points to this particular
knot list. The \\{future\_pen} option occurs only as an output of \\{scan%
\_primary}
and \\{scan\_secondary}, not as an output of \\{scan\_tertiary} or \\{scan%
\_expression}.

\smallskip\hang
$\\{cur\_type}=\\{edges\_type}$ means that \\{cur\_exp} points to a edges
header node.
Nobody else points to this particular set of edges.

\smallskip\hang
$\\{cur\_type}=\\{unknown\_edges}$ means that \\{cur\_exp} points to a capsule
node that is either \\{edges\_type} or in the ring of variables equivalent
to at least one undefined edges variable.

\smallskip\hang
$\\{cur\_type}=\\{path\_type}$ means that \\{cur\_exp} points to a the first
node of
a path; nobody else points to this particular path. The control points of
the path will have been chosen, except when it's a one-node \\{fragment} that
has been output by \\{scan\_tertiary}.

\smallskip\hang
$\\{cur\_type}=\\{unknown\_path}$ means that \\{cur\_exp} points to a capsule
node that is either \\{path\_type} or in the ring of variables equivalent
to at least one undefined path variable.

\smallskip\hang
$\\{cur\_type}=\\{transform\_type}$ means that \\{cur\_exp} points to a capsule
node whose type is \\{transform\_type}. The \\{value} part of this capsule
points to a transform node that contains six numeric values,
each of which is \\{dependent} or \\{proto\_dependent} or \\{known}.

\smallskip\hang
$\\{cur\_type}=\\{pair\_type}$ means that \\{cur\_exp} points to a capsule
node whose type is \\{pair\_type}. The \\{value} part of this capsule
points to a pair node that contains two numeric values,
each of which is \\{dependent} or \\{proto\_dependent} or \\{known}.

\smallskip\hang
$\\{cur\_type}=\\{known}$ means that \\{cur\_exp} is a \\{scaled} value.

\smallskip\hang
$\\{cur\_type}=\\{dependent}$ means that \\{cur\_exp} points to a dependency
list
that has {\sl not\/} yet been included in the set of lists reachable
from \\{dep\_head}.

\smallskip\hang
$\\{cur\_type}=\\{proto\_dependent}$ means that \\{cur\_exp} points to a
proto-dependency list that has {\sl not\/} yet been included in the set of
lists reachable from \\{dep\_head}.

\smallskip\hang
$\\{cur\_type}=\\{token\_list}$ means that \\{cur\_exp} points to a linked list
of
tokens. This case arises only on the left-hand side of an assignment
(`\.{:=}') operation, under very special circumstances.

\smallskip\noindent
The possible settings of \\{cur\_type} have been listed here in increasing
numerical order. Notice that \\{cur\_type} will never be \\{independent} or
\\{suffixed\_macro} or \\{unsuffixed\_macro}, although variables of those
three types are allowed. Conversely, \MF\ has no variables of type
\\{vacuous} or \\{token\_list}.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{cur\_type}\K\\{vacuous}$;\5
$\\{cur\_exp}\K0$;\par
\fi

\M668. Capsules are two-word nodes that have a similar meaning
to \\{cur\_type} and \\{cur\_exp}. Such nodes have $\\{name\_type}=\\{capsule}$
and $\\{link}\L\\{null1}$; and their \\{type} field is one of the possibilities
for
\\{cur\_type} listed above.

The \\{value} field of a capsule is, in most cases, the value that
corresponds to its \\{type} as \\{cur\_exp} corresponds to \\{cur\_type};
however, when \\{cur\_exp} would
point to a capsule (i.e., when $\\{type}=\\{unknown\_boolean}$, \\{unknown%
\_string},
\\{unknown\_pen}, \\{unknown\_edges}, \\{unknown\_path}, \\{transform\_type},
or \\{pair\_type}), no extra layer of indirection is present; the \\{value}
field
is what would be called $\\{value}(\\{cur\_exp})$ if it had not been
encapsulated.
Furthermore, if the type is \\{dependent} or \\{proto\_dependent}, the %
\\{value}
field of a capsule is replaced by \\{dep\_list} and \\{prev\_dep} fields,
since dependency lists in capsules are always part of the general
\\{dep\_list} structure.

The \\{get\_x\_next} routine is careful not to change the values of \\{cur%
\_type}
and \\{cur\_exp} when it gets an expanded token. However, \\{get\_x\_next}
might
call a macro, which might parse an expression, which might execute lots of
commands in a group; hence it's possible that, say \\{cur\_type} might
change from \\{unknown\_boolean} to \\{boolean\_type}, or from \\{dependent} to
\\{known}, during the time \\{get\_x\_next} is called. The programs below
are careful to stash sensitive intermediate results in capsules,
so that \MF's generality doesn't cause trouble.

Here is a procedure that illustrates these conventions. It takes
the contents of (\\{cur\_type},\\{cur\_exp}) and stashes them away in a
capsule. It is not used when $\\{cur\_type}=\\{token\_list}$.
After the operation, $\\{cur\_type}=\\{vacuous}$; hence there is no need to
copy path lists or to update reference counts, etc.

The special link \\{null1} is put on the capsule returned by
\\{stash\_cur\_exp}, because this procedure is used to store macro parameters
that must be easily distinguishable from token lists.

\Y\P$\4\X668:Declare the stashing/unstashing routines\X\S$\6
\X669:Declare the procedure called \\{stash\_in}\X\6
\4\&{function}\1\  \37\\{stash\_cur\_exp}: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the capsule that will be returned}\2\6
\&{begin} \37\&{case} $\\{cur\_type}$ \1\&{of}\6
\4$\\{unknown\_boolean},\39\\{unknown\_string},\39\\{unknown\_pen},\39%
\\{unknown\_edges},\39\\{unknown\_path},\39\\{transform\_type},\39\\{pair%
\_type}$: \37$\|p\K\\{cur\_exp}$;\6
\4\&{othercases} \37\&{begin} \37$\|p\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{name\_type}(\|p)\K\\{capsule}$;\5
$\\{stash\_in}(\|p)$;\6
\&{end}\2\6
\&{endcases};\6
$\\{cur\_type}\K\\{vacuous}$;\5
$\\{link}(\|p)\K\\{null1}$;\5
$\\{stash\_cur\_exp}\K\|p$;\6
\&{end};\par
\A section~670.
\U section~575.\fi

\M669. \P$\X669:Declare the procedure called \\{stash\_in}\X\S$\6
\4\&{procedure}\1\  \37$\\{stash\_in}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the tail of a dependency list}\2\6
\&{begin} \37$\\{type}(\|p)\K\\{cur\_type}$;\5
$\\{value}(\|p)\K\\{cur\_exp}$;\6
\&{if} $\\{cur\_type}\L\\{proto\_dependent}$ \1\&{then}\6
\&{if} $\\{cur\_type}\G\\{dependent}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{cur\_exp}$;\6
\&{while} $\\{info}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{link}(\|q)\K\\{link}(\\{dep\_head})$;\5
$\\{prev\_dep}(\\{link}(\\{dep\_head}))\K\|q$;\5
$\\{link}(\\{dep\_head})\K\|p$;\5
$\\{prev\_dep}(\|p)\K\\{dep\_head}$;\5
$\\{dep\_list}(\|p)\K\\{cur\_exp}$;\6
\&{end};\2\2\6
$\\{cur\_type}\K\\{vacuous}$;\6
\&{end};\par
\U section~668.\fi

\M670. The inverse of \\{stash\_cur\_exp} is the following procedure, which
deletes an unnecessary capsule and puts its contents into \\{cur\_type}
and \\{cur\_exp}. It is assumed that \\{cur\_type} and \\{cur\_exp} do not
contain any relevant information.

\Y\P$\4\X668:Declare the stashing/unstashing routines\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{unstash\_cur\_exp}(\|p:\\{pointer})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the tail of a dependency list}\2\6
\&{begin} \37$\\{cur\_type}\K\\{type}(\|p)$;\6
\&{case} $\\{cur\_type}$ \1\&{of}\6
\4$\\{unknown\_boolean},\39\\{unknown\_string},\39\\{unknown\_pen},\39%
\\{unknown\_edges},\39\\{unknown\_path},\39\\{transform\_type},\39\\{pair%
\_type}$: \37$\\{cur\_exp}\K\|p$;\6
\4\&{othercases} \37\&{begin} \37\&{if} $(\\{cur\_type}\L\\{proto\_dependent})%
\W(\\{cur\_type}\G\\{dependent})$ \1\&{then}\6
\&{begin} \37$\|q\K\\{dep\_list}(\|p)$;\6
\&{while} $\\{info}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{prev\_dep}(\\{link}(\|q))\K\\{prev\_dep}(\|p)$;\5
$\\{link}(\\{prev\_dep}(\|p))\K\\{link}(\|q)$;\5
$\\{cur\_exp}\K\\{dep\_list}(\|p)$;\6
\&{end};\6
\4\&{else} $\\{cur\_exp}\K\\{value}(\|p)$;\2\6
$\\{free\_node}(\|p,\39\\{value\_node\_size})$;\6
\&{end}\2\6
\&{endcases};\6
\&{end};\par
\fi

\M671. Boolean constants are really simple.

\Y\P\D \37$\\{true\_code}=1$\par
\P\D \37$\\{false\_code}=0$\par
\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"true"},\39\\{boolean\_const},\39\\{true\_code})$;\6
$\\{primitive}(\.{"false"},\39\\{boolean\_const},\39\\{false\_code})$;\par
\fi

\M672. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{boolean\_const}: \37\&{if} $\mathbin{\&{mod}}=\\{true\_code}$ \1\&{then}\5
$\\{print}(\.{"true"})$\ \&{else} $\\{print}(\.{"false"})$;\2\par
\fi

\M673. The following procedure prints the values of expressions in an
abbreviated format. If its first parameter \|p is null, the value of
$(\\{cur\_type},\\{cur\_exp})$ is displayed; otherwise \|p should be a capsule
containing the desired value. The second parameter is \\{true} if dependency
lists should be displayed in full; otherwise a dependency list will be
abbreviated to `\.{<dependent>}' unless it consists of a single term.

\Y\P$\4\X673:Declare the procedure called \\{print\_exp}\X\S$\6
\X676:Declare the procedure called \\{print\_dp}\X\6
\4\&{procedure}\1\  \37$\\{print\_exp}(\|p:\\{pointer};\,\35\\{verbose}:%
\\{boolean})$;\2\6
\&{begin} \37\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\|t\K\\{cur\_type}$;\5
$\|v\K\\{cur\_exp}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|t\K\\{type}(\|p)$;\6
\&{if} $\|t<\\{dependent}$ \1\&{then}\5
$\|v\K\\{value}(\|p)$\ \&{else} $\|v\K\\{dep\_list}(\|p)$;\2\6
\&{end};\2\6
\X674:Print an abbreviated value of \|v with format depending on \|t\X;\6
\&{end};\par
\U section~575.\fi

\M674. \P$\X674:Print an abbreviated value of \|v with format depending on \|t%
\X\S$\6
\&{case} $\|t$ \1\&{of}\6
\4\\{vacuous}: \37$\\{print}(\.{"<null>"})$;\6
\4\\{boolean\_type}: \37\&{if} $\|v=\\{true\_code}$ \1\&{then}\5
$\\{print}(\.{"true"})$\ \&{else} $\\{print}(\.{"false"})$;\2\6
\4$\\{unknown\_boolean},\39\\{unknown\_string},\39\\{unknown\_pen},\39%
\\{unknown\_edges},\39\\{unknown\_path}$: \37\X677:Display a variable that's
been declared but not defined\X;\6
\4\\{string\_type}: \37$\\{print}(\|v)$;\6
\4$\\{pen\_type},\39\\{edges\_type},\39\\{path\_type},\39\\{transform\_type}$: %
\37\&{begin} \37$\\{print\_char}(\.{"<"})$;\5
$\\{print\_type}(\|t)$;\5
$\\{print\_char}(\.{">"})$;\6
\&{end};\6
\4\\{future\_pen\_type}: \37$\\{print}(\.{"<future\ pen>"})$;\6
\4\\{pair\_type}: \37\X675:Display a pair of numerics\X;\6
\4\\{known}: \37$\\{print\_scaled}(\|v)$;\6
\4$\\{dependent},\39\\{proto\_dependent}$: \37$\\{print\_dp}(\|t,\39\|v,\39%
\\{verbose})$;\6
\4\&{othercases} \37$\\{confusion}(\.{"exp"})$\2\6
\&{endcases}\par
\U section~673.\fi

\M675. \P$\X675:Display a pair of numerics\X\S$\6
\&{begin} \37\&{if} $\|p=\\{null}$ \1\&{then}\5
$\|v\K\\{value}(\|v)$;\2\6
$\\{print\_char}(\.{"("})$;\6
\&{if} $\\{type}(\\{x\_part\_loc}(\|v))=\\{known}$ \1\&{then}\5
$\\{print\_scaled}(\\{value}(\\{x\_part\_loc}(\|v)))$\6
\4\&{else} $\\{print\_dp}(\\{type}(\\{x\_part\_loc}(\|v)),\39\\{dep\_list}(\\{x%
\_part\_loc}(\|v)),\39\\{verbose})$;\2\6
$\\{print\_char}(\.{","})$;\6
\&{if} $\\{type}(\\{y\_part\_loc}(\|v))=\\{known}$ \1\&{then}\5
$\\{print\_scaled}(\\{value}(\\{y\_part\_loc}(\|v)))$\6
\4\&{else} $\\{print\_dp}(\\{type}(\\{y\_part\_loc}(\|v)),\39\\{dep\_list}(\\{y%
\_part\_loc}(\|v)),\39\\{verbose})$;\2\6
$\\{print\_char}(\.{")"})$;\6
\&{end}\par
\U section~674.\fi

\M676. \P$\X676:Declare the procedure called \\{print\_dp}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_dp}(\|t:\\{small\_number};\,\35\|p:%
\\{pointer};\,\35\\{verbose}:\\{boolean})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the node following \|p}\2\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\6
\&{if} $(\\{info}(\|q)=\\{null})\V\\{verbose}$ \1\&{then}\5
$\\{print\_dependency}(\|p,\39\|t)$\6
\4\&{else} $\\{print}(\.{"<dependent>"})$;\2\6
\&{end};\par
\U section~673.\fi

\M677. \P$\X677:Display a variable that's been declared but not defined\X\S$\6
\&{begin} \37$\\{print\_char}(\.{"<"})$;\5
$\\{print\_type}(\|t)$;\5
$\\{print\_char}(\.{">"})$;\6
\1\&{repeat} \37$\|v\K\\{value}(\|v)$;\6
\4\&{until}\5
$\\{name\_type}(\|v)\I\\{capsule}$;\2\6
$\\{print\_name}(\|v)$;\6
\&{end}\par
\U section~674.\fi

\M678. When errors are detected during parsing, it is often helpful to
display an expression just above the error message.

\Y\P\D \37$\\{exp\_err}(\#)\S\\{disp\_err}(\\{null},\39\#)$\C{displays the
current expression}\par
\Y\P\4\&{procedure}\1\  \37$\\{disp\_err}(\|p:\\{pointer};\,\35\|s:\\{str%
\_number})$;\2\6
\&{begin} \37\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
\\{print\_ln};\5
$\\{print\_exp}(\|p,\39\\{true})$;\C{``verbose'' printing of the expression}\6
$\\{print\_nl}(\.{"!\ "})$;\5
$\\{print}(\|s)$;\6
\&{end};\par
\fi

\M679. If \\{cur\_type} and \\{cur\_exp} contain relevant information that
should
be recycled, we will use the following procedure, which changes \\{cur\_type}
to \\{known} and stores a given value in \\{cur\_exp}.

\Y\P\4\&{procedure}\1\  \37$\\{flush\_cur\_exp}(\|v:\\{scaled})$;\2\6
\&{begin} \37\&{case} $\\{cur\_type}$ \1\&{of}\6
\4$\\{unknown\_boolean},\39\\{unknown\_string},\39\\{unknown\_pen},\39%
\\{unknown\_edges},\39\\{unknown\_path},\39\\{transform\_type},\39\\{pair%
\_type}$: \37\&{begin} \37$\\{recycle\_value}(\\{cur\_exp})$;\5
$\\{free\_node}(\\{cur\_exp},\39\\{value\_node\_size})$;\6
\&{end};\6
\4\\{pen\_type}: \37$\\{delete\_pen\_ref}(\\{cur\_exp})$;\6
\4$\\{future\_pen},\39\\{path\_type}$: \37$\\{toss\_knot\_list}(\\{cur\_exp})$;%
\6
\4\\{edges\_type}: \37$\\{toss\_edges}(\\{cur\_exp})$;\6
\4$\\{dependent},\39\\{proto\_dependent},\39\\{token\_list}$: \37$\\{flush%
\_node\_list}(\\{cur\_exp})$;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
$\\{cur\_type}\K\\{known}$;\5
$\\{cur\_exp}\K\|v$;\6
\&{end};\par
\fi

\M680. \P$\X680:Declare the procedure called \\{recycle\_value}\X\S$\6
\\{FIXTHIS}\par
\U section~231.\fi

\M681. A global variable called \\{beginning} is set \\{true} just before
\MF\ calls \\{scan\_expression} at the beginning of what could turn out
to be an equation or an assignment. Then \\{scan\_expression} calls
\\{scan\_tertiary}, which calls \\{scan\_secondary}, which calls
\\{scan\_primary}, which sets $\\{beginning}\K\\{false}$. In this way each of
the scanning routines ``knows'' when it has been called at the beginning
of a potential equation or assignment. This affects the parsing,
because an `\.{=}' sign is not considered to be a relation that
produces boolean expressions, and a variable to the left of `\.{:=}'
is converted to a token list rather than a value.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{beginning}: \37\\{boolean};\C{are we beginning a potential equation or
assignment?}\par
\fi

\M682. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{beginning}\K\\{false}$;\par
\fi

\N683.  \[xx] Parsing primary expressions.
The first parsing routine, \\{scan\_primary}, is also the most complicated,
since it involves so many different cases. But each case---with one
exception---is fairly simple by itself.

The value of \\{cur\_cmd} at the beginning of \\{scan\_primary} should be
between \\{min\_primary\_command} and \\{max\_primary\_command}, inclusive.

\Y\P\X684:Declare subroutines needed for expression parsing\X\6
\4\&{procedure}\1\  \37\\{scan\_primary};\6
\4\&{label} \37$\\{restart},\39\\{common\_ending},\39\\{done},\39\\{done1},\39%
\\{found},\39\\{exit}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for list manipulation}\6
\|c: \37\\{quarterword};\C{a primitive operation code}\6
\\{start\_of\_stmt}: \37\\{boolean};\C{initial value of \\{beginning}}\6
$\\{l\_delim},\39\\{r\_delim}$: \37\\{pointer};\C{hash addresses of a delimiter
pair}\6
\X688:Other local variables for \\{scan\_primary}\X\2\6
\&{begin} \37$\\{start\_of\_stmt}\K\\{beginning}$;\5
$\\{beginning}\K\\{false}$;\6
\4\\{restart}: \37\&{if} $\\{arith\_error}$ \1\&{then}\5
\\{clear\_arith};\2\6
\X685:Supply diagnostic information, if requested\X;\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4\\{left\_delimiter}: \37\X686:Scan a delimited primary\X;\6
\4\\{begin\_group}: \37\X689:Scan a grouped primary\X;\6
\4\\{boolean\_const}: \37\X691:Scan a boolean constant\X;\6
\4\\{string\_token}: \37\X692:Scan a string constant\X;\6
\4\\{numeric\_token}: \37\X695:Scan a primary that starts with a numeric token%
\X;\6
\4\\{nullary}: \37\X693:Scan a nullary operation\X;\6
\4$\\{unary},\39\\{type\_name},\39\\{plus\_or\_minus}$: \37\X694:Scan a unary
operation\X;\6
\4\\{primary\_binary}: \37\X696:Scan a binary operation with `\&{of}' between
its operands\X;\6
\4$\\{internal},\39\\{expr\_arg},\39\\{name\_token}$: \37\X699:Scan a variable
primary; \&{goto} \\{restart} if it turns out to be a macro\X;\6
\4\&{othercases} \37\&{begin} \37$\\{bad\_exp}(\.{"A\ primary"})$;\5
\&{goto} \37\\{restart};\6
\&{end}\2\6
\&{endcases};\6
\4\\{common\_ending}: \37\\{get\_x\_next};\C{the routines \&{return} if they
don't want this}\6
\4\\{exit}: \37\&{end};\par
\fi

\M684. \P$\X684:Declare subroutines needed for expression parsing\X\S$\6
\4\&{procedure}\1\  \37$\\{bad\_exp}(\|s:\\{str\_number})$;\2\6
\&{begin} \37$\\{print\_err}(\|s)$;\5
$\\{print}(\.{"\ expression\ can\'t\ begin\ with\ \`"})$;\5
$\\{print\_cmd\_mod}(\\{cur\_cmd},\39\\{cur\_mod})$;\5
$\\{print\_char}(\.{"\'"})$;\5
$\\{help4}(\.{"I\'m\ afraid\ I\ need\ some\ sort\ of\ value\ in\ order\ to\
continue,"})$\6
$(\.{"so\ I\'ve\ tentatively\ inserted\ \`0\'.\ You\ may\ want\ to"})$\6
$(\.{"delete\ this\ zero\ and\ insert\ something\ else;"})$\6
$(\.{"see\ Chapter\ xx\ of\ The\ METAFONTbook\ for\ an\ example."})$;\5
\\{back\_input};\5
$\\{cur\_sym}\K0$;\5
$\\{cur\_cmd}\K\\{numeric\_token}$;\5
$\\{cur\_mod}\K0$;\5
\\{ins\_error};\5
\\{get\_x\_next};\6
\&{end};\par
\A sections~690, 702, 704, 711, 720, 723, 726, 737, 749, and~774.
\U section~683.\fi

\M685. \P$\X685:Supply diagnostic information, if requested\X\S$\6
\&{debug} \37\&{if} $\\{panicking}$ \1\&{then}\5
$\\{check\_mem}(\\{false})$;\ \2\6
\&{gubed}\6
\&{if} $\\{interrupt}\I0$ \1\&{then}\6
\&{if} $\\{OK\_to\_interrupt}$ \1\&{then}\6
\&{begin} \37\\{back\_input};\5
\\{check\_interrupt};\5
\\{get\_x\_next};\6
\&{end}\2\2\par
\U section~683.\fi

\M686. \P$\X686:Scan a delimited primary\X\S$\6
\&{begin} \37$\\{l\_delim}\K\\{cur\_sym}$;\5
$\\{r\_delim}\K\\{cur\_mod}$;\5
\\{get\_x\_next};\5
\\{scan\_expression};\6
\&{if} $(\\{cur\_cmd}=\\{comma})\W(\\{cur\_type}\G\\{dependent})$ \1\&{then}\5
\X687:Scan the second of a pair of numerics\X\6
\4\&{else} $\\{check\_delimiter}(\\{l\_delim},\39\\{r\_delim})$;\2\6
\&{end}\par
\U section~683.\fi

\M687. \P$\X687:Scan the second of a pair of numerics\X\S$\6
\&{begin} \37$\|p\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{type}(\|p)\K\\{pair\_type}$;\5
$\\{name\_type}(\|p)\K\\{capsule}$;\5
$\\{init\_big\_node}(\\{pair\_node\_size})$;\5
$\\{stash\_in}(\\{x\_part\_loc}(\|p))$;\5
\\{get\_x\_next};\5
\\{scan\_expression};\6
\&{if} $\\{cur\_type}<\\{dependent}$ \1\&{then}\6
\&{begin} \37$\\{exp\_err}(\.{"Nonnumeric\ ypart\ has\ been\ replaced\ by\
0"})$;\5
$\\{help4}(\.{"I\ thought\ you\ were\ giving\ me\ a\ pair\ \`(x,y)\';\ but"})$\6
$(\.{"after\ finding\ a\ nice\ xpart\ \`x\'\ I\ found\ a\ ypart\ \`y\'"})$\6
$(\.{"that\ isn\'t\ of\ numeric\ type.\ So\ I\'ve\ changed\ y\ to\ zero."})$\6
$(\.{"(The\ y\ that\ I\ didn\'t\ like\ appears\ above\ the\ error\
message.)"})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(0)$;\6
\&{end};\2\6
$\\{stash\_in}(\\{y\_part\_loc}(\|p))$;\5
$\\{check\_delimiter}(\\{l\_delim},\39\\{r\_delim})$;\5
$\\{cur\_type}\K\\{pair\_type}$;\5
$\\{cur\_exp}\K\|p$;\6
\&{end}\par
\U section~686.\fi

\M688. The local variable \\{group\_line} keeps track of the line
where a \&{begingroup} command occurred; this will be useful
in an error message if the group doesn't actually end.

\Y\P$\4\X688:Other local variables for \\{scan\_primary}\X\S$\6
\4\\{group\_line}: \37\\{integer};\C{where a group began}\par
\A section~698.
\U section~683.\fi

\M689. \P$\X689:Scan a grouped primary\X\S$\6
\&{begin} \37$\\{group\_line}\K\\{line}$;\5
\\{begin\_a\_group};\6
\1\&{repeat} \37\\{do\_statement};\C{ends with $\\{cur\_cmd}\G\\{semicolon}$}\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{semicolon}$;\2\6
\&{if} $\\{cur\_cmd}\I\\{end\_group}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"A\ group\ begun\ on\ line\ "})$;\5
$\\{print\_int}(\\{line})$;\5
$\\{print}(\.{"\ never\ ended"})$;\5
$\\{help2}(\.{"I\ saw\ a\ \`begingroup\'\ back\ there\ that\ hasn\'t\ been\
matched"})$\6
$(\.{"by\ \`endgroup\'.\ So\ I\'ve\ inserted\ \`endgroup\'\ now."})$;\5
\\{back\_error};\5
$\\{cur\_cmd}\K\\{end\_group}$;\5
$\\{cur\_sym}\K\\{frozen\_end\_group}$;\6
\&{end};\2\6
\\{end\_a\_group};\6
\&{end}\par
\U section~683.\fi

\M690. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{begin\_a\_group};\2\6
\&{begin} \37\&{if} $\\{internal}[\\{tracing\_commands}]>0$ \1\&{then}\5
$\\{show\_cmd\_mod}(\\{cur\_cmd},\39\\{cur\_mod})$;\C{FIXTHIS: do what's need
to initialize save/restore mechanism}\2\6
\&{end}\7
\4\&{procedure}\1\  \37\\{end\_a\_group};\2\6
\&{begin} \37\C{FIXTHIS: restore saved values}\6
\&{end}\par
\fi

\M691. \P$\X691:Scan a boolean constant\X\S$\6
\&{begin} \37$\\{cur\_type}\K\\{boolean\_type}$;\5
$\\{cur\_exp}\K\\{cur\_mod}$;\6
\&{end}\par
\U section~683.\fi

\M692. \P$\X692:Scan a string constant\X\S$\6
\&{begin} \37$\\{cur\_type}\K\\{string\_type}$;\5
$\\{cur\_exp}\K\\{cur\_mod}$;\6
\&{end}\par
\U section~683.\fi

\M693. Later we'll come to procedures that perform actual operations like
addition, square root, and so on; our purpose now is to do the parsing.
But we might as well mention those future procedures now, so that the
suspense won't be too bad:

\smallskip
$\\{do\_nullary}(\|c)$ does primary operations that have no operands (e.g.,
`\&{pencircle}');

\smallskip
$\\{do\_unary}(\|c)$ applies a primitive operation to the current expression;

\smallskip
$\\{do\_binary}(\|p,\|c)$ applies a primitive operation to the capsule~\|p
and the current expression.

\Y\P$\4\X693:Scan a nullary operation\X\S$\6
$\\{do\_nullary}(\\{cur\_mod})$\par
\U section~683.\fi

\M694. \P$\X694:Scan a unary operation\X\S$\6
\&{begin} \37$\|c\K\\{cur\_mod}$;\5
\\{get\_x\_next};\5
\\{scan\_primary};\5
$\\{do\_unary}(\|c)$;\5
\&{return};\6
\&{end}\par
\U section~683.\fi

\M695. A numeric token might be a primary by itself, or it might be the
numerator of a fraction composed solely of numeric tokens, or it might
multiply the primary that follows (provided that the primary doesn't begin
with a plus sign or a minus sign). The code here uses the fact that
$\\{max\_primary\_command}=\\{plus\_or\_minus}$. If a fraction is found that
is less than unity, we try to retain higher precision when we
use it in scalar multiplication.

\Y\P$\4\X695:Scan a primary that starts with a numeric token\X\S$\6
\&{begin} \37$\\{cur\_exp}\K\\{cur\_mod}$;\5
$\\{cur\_type}\K\\{known}$;\5
\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}\I\\{slash}$ \1\&{then}\5
$\\{denom}\K0$\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}\I\\{numeric\_token}$ \1\&{then}\6
\&{begin} \37\\{back\_input};\5
$\\{cur\_cmd}\K\\{slash}$;\5
$\\{cur\_mod}\K\\{over}$;\5
$\\{cur\_sym}\K\\{frozen\_slash}$;\5
\&{return};\6
\&{end};\2\6
$\\{num}\K\\{cur\_exp}$;\5
$\\{denom}\K\\{cur\_mod}$;\5
$\\{cur\_exp}\K\\{make\_scaled}(\\{num},\39\\{denom})$;\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}\G\\{min\_primary\_command}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}<\\{max\_primary\_command}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{stash\_cur\_exp}$;\5
\\{scan\_primary};\6
\&{if} $(\\{abs}(\\{num})\G\\{abs}(\\{denom}))\V(\\{cur\_type}<\\{pair\_type})$
\1\&{then}\5
$\\{do\_binary}(\|p,\39\\{times})$\6
\4\&{else} \&{begin} \37$\\{frac\_mult}(\\{take\_fraction}(\\{num},\39%
\\{denom}))$;\5
$\\{free\_node}(\|p,\39\\{value\_node\_size})$;\6
\&{end};\2\6
\&{end};\2\2\6
\&{return};\6
\&{end}\par
\U section~683.\fi

\M696. \P$\X696:Scan a binary operation with `\&{of}' between its operands\X\S$%
\6
\&{begin} \37$\|c\K\\{cur\_mod}$;\5
\\{get\_x\_next};\5
\\{scan\_expression};  \6
\&{if} $\\{cur\_cmd}\I$ \1\&{of} \&{then} \6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`of\'\ has\ been\ inserted\ for"})$;%
\5
$\\{print\_cmd\_mod}(\\{primary\_binary},\39\|c)$;\5
$\\{help1}(\.{"I\'ve\ got\ the\ first\ argument;\ will\ look\ now\ for\ the\
other."})$;\5
\\{back\_error};\6
\&{end};\5
$\|p\K\\{stash\_cur\_exp}$;\5
\\{get\_x\_next};\5
\\{scan\_primary};\5
$\\{do\_binary}(\|p,\39\|c)$;\5
\&{return}; \6
\&{end} \par
\U section~683.\fi

\M697. The most difficult part of \\{scan\_primary} has been saved for last,
since
it was necessary to build up some confidence first. We can now face the task
of scanning a variable.

As we scan a variable, we build a token list containing the relevant
names and subscript values, simultaneously following along in the
``generic'' structure to see if we are actually dealing with a macro
instead of a value.

The local variables \\{pre\_head} and \\{post\_head} will point to the
beginning
of the prefix and suffix lists; \\{tail} will point to the end of the list
that is currently growing.

Another local variable, \\{tt}, contains partial information about the
declared type of the variable-so-far. If $\\{tt}\G\\{unsuffixed\_macro}$, the
relation $\\{tt}=\\{type}(\|q)$ will always hold. If $\\{tt}=\\{undefined}$,
the routine
doesn't bother to update its information about type. And if
$\\{undefined}<\\{tt}<\\{unsuffixed\_macro}$, the precise value of \\{tt} isn't
critical.

\fi

\M698. \P$\X688:Other local variables for \\{scan\_primary}\X\mathrel{+}\S$\6
\4$\\{pre\_head},\39\\{post\_head},\39\\{tail}$: \37\\{pointer};\C{prefix and
suffix list variables}\6
\4\\{tt}: \37\\{small\_number};\C{approximation to the type of the
variable-so-far}\6
\4\|t: \37\\{pointer};\C{a token}\6
\4\\{macro\_ref}: \37\\{pointer};\C{reference count for a suffixed macro}\par
\fi

\M699. \P$\X699:Scan a variable primary; \&{goto} \\{restart} if it turns out
to be a macro\X\S$\6
\&{begin} \37\&{if} $\\{cur\_cmd}\I\\{name\_token}$ \1\&{then}\5
\X709:Make a parameter act like a variable; \&{goto} \\{found} or \&{return} as
appropriate\X;\2\6
\&{if} $\\{cur\_mod}=\\{null}$ \1\&{then}\5
$\\{tt}\K\\{undefined}$\6
\4\&{else} \&{begin} \37$\|q\K\\{cur\_mod}$;\5
$\\{tt}\K\\{type}(\|q)$;\6
\&{end};\2\6
$\\{pre\_head}\K\\{get\_avail}$;\5
$\\{tail}\K\\{pre\_head}$;\5
$\\{post\_head}\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|t\K\\{cur\_tok}$;\6
\&{if} $\\{tt}\G\\{unsuffixed\_macro}$ \1\&{then}\6
\&{if} $\\{tt}>\\{unsuffixed}$ \1\&{then}\C{$\\{tt}=\\{suffixed\_macro}$}\6
\&{begin} \37$\\{post\_head}\K\\{get\_avail}$;\5
$\\{tail}\K\\{post\_head}$;\5
$\\{tt}\K\\{undefined}$;\5
$\\{macro\_ref}\K\\{value}(\|q)$;\5
$\\{add\_ref}(\\{macro\_ref})$;\6
\&{end}\6
\4\&{else} \X707:Set up unsuffixed macro call and \&{goto} \\{restart}\X;\2\2\6
$\\{link}(\\{tail})\K\|t$;\5
\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}=\\{left\_bracket}$ \1\&{then}\5
\X700:Scan for a subscript; replace \\{cur\_cmd} by \\{numeric\_token} if found%
\X;\2\6
\&{if} $\\{cur\_cmd}\I\\{numeric\_token}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}\I\\{name\_token}$ \1\&{then}\5
\&{goto} \37\\{done};\2\2\6
$\\{tail}\K\|t$;\6
\&{if} $\\{tt}\I\\{undefined}$ \1\&{then}\5
\X705:Look up the new values of \\{tt} and \|q\X;\2\6
\&{end};\2\6
\4\\{done}: \37\X706:Handle unusual cases that masquerade as variables, and %
\&{goto} \\{restart} or \&{return} if appropriate\X;\6
\4\\{found}: \37\X710:Copy the variable's value into $(\\{cur\_type},\\{cur%
\_exp})$ and \&{return}\X;\6
\&{end}\par
\U section~683.\fi

\M700. \P$\X700:Scan for a subscript; replace \\{cur\_cmd} by \\{numeric%
\_token} if found\X\S$\6
\&{begin} \37\\{get\_x\_next};\5
\\{get\_expression};\6
\&{if} $\\{cur\_cmd}\I\\{right\_bracket}$ \1\&{then}\5
\X701:Put the left bracket and the expression back to be rescanned\X\6
\4\&{else} \&{begin} \37\&{if} $\\{cur\_type}\I\\{known}$ \1\&{then}\5
\\{bad\_subscript};\2\6
$\\{cur\_cmd}\K\\{numeric\_token}$;\5
$\\{cur\_mod}\K\\{cur\_exp}$;\5
$\\{cur\_sym}\K0$;\6
\&{end};\2\6
\&{end}\par
\U section~699.\fi

\M701. The left bracket that we thought was introducing a subscript might have
actually been the left bracket in a mediation construction like `\.{x[a,b]}'.
So we don't issue an error message at this point; but we do want to back up
so as to avoid any embarrassment about our incorrect assumption.

\Y\P$\4\X701:Put the left bracket and the expression back to be rescanned\X\S$\6
\&{begin} \37\\{back\_input};\C{that was the token following the current
expression}\6
\\{back\_expr};\5
$\\{cur\_cmd}\K\\{left\_bracket}$;\5
$\\{cur\_sym}\K\\{frozen\_left\_bracket}$;\6
\&{end}\par
\U sections~700 and~721.\fi

\M702. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{back\_expr};\C{puts the current expression back to be
read again}\2\6
\&{begin} \37$\\{begin\_token\_list}(\\{identity\_macro},\39\\{identity})$;\5
$\\{incr}(\\{param\_ptr})$;\6
\&{if} $\\{param\_ptr}>\\{max\_param\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_param\_stack}\K\\{param\_ptr}$;\6
\&{if} $\\{max\_param\_stack}>\\{param\_size}$ \1\&{then}\5
$\\{overflow}(\.{"parameter\ stack\ size"},\39\\{param\_size})$;\2\6
\&{end};\2\6
$\\{param\_stack}[\\{param\_ptr}-1]\K\\{stash\_cur\_exp}$;\6
\&{end};\par
\fi

\M703. The \\{identity\_macro} is predeclared to reproduce its lone argument.

\Y\P$\4\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}\S$\6
$\\{info}(\\{identity\_macro})\K\\{expr\_base}$;\par
\fi

\M704. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{bad\_subscript};\2\6
\&{begin} \37$\\{exp\_err}(\.{"Improper\ subscript\ has\ been\ replaced\ by\
zero"})$;\5
$\\{help3}(\.{"A\ bracketed\ subscript\ must\ have\ a\ known\ numeric\
value;"})$\6
$(\.{"the\ unknown\ value\ that\ I\ found\ appears\ just\ above\ this"})$\6
$(\.{"error\ message.\ Proceed,\ and\ I\'ll\ try\ a\ zero\ subscript."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(0)$;\6
\&{end};\par
\fi

\M705. Every time we call \\{get\_x\_next}, there's a chance that the variable
we've
been looking at will disappear. Thus, we cannot safely keep \|q pointing
into the variable structure; we need to start searching from the root each
time.

\Y\P$\4\X705:Look up the new values of \\{tt} and \|q\X\S$\6
\&{begin} \37$\|p\K\\{link}(\\{pre\_head})$;\5
$\|q\K\\{info}(\|p)$;\5
$\\{tt}\K\\{undefined}$;\6
\&{if} $\\{eq\_type}(\|q)=\\{name\_token}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{equiv}(\|q)$;\6
\~ \1\&{loop}\ \&{begin} \37$\|p\K\\{link}(\|p)$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{tt}\K\\{type}(\|q)$;\5
\&{goto} \37\\{done1};\6
\&{end};\2\6
\&{if} $\\{type}(\|q)\I\\{structured}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\|q\K\\{link}(\\{attr\_head}(\|q))$;\C{the \\{generic\_subscript} attribute}\6
\&{if} $\|p>\\{hi\_mem\_base}$ \1\&{then}\6
\&{begin} \37\1\&{repeat} \37$\|q\K\\{link}(\|q)$;\6
\4\&{until}\5
$\\{attr\_loc}(\|q)\G\\{info}(\|p)$;\2\6
\&{if} $\\{attr\_loc}(\|q)>\\{info}(\|p)$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\4\\{done1}: \37\&{end}\par
\U section~699.\fi

\M706. How do things stand now? Well, we have scanned an entire variable name,
including possible subscripts and/or attributes; \\{cur\_cmd}, \\{cur\_mod},
and
\\{cur\_sym} represent the token that follows. If $\\{post\_head}=\\{null}$, a
token list for this variable name starts at $\\{link}(\\{pre\_head})$, with all
subscripts evaluated. But if $\\{post\_head}\I\\{null}$, the variable turned
out
to be a suffixed macro; \\{pre\_head} is the head of the prefix list, while
\\{post\_head} is the head of a token list containing both `\.{\AT!}' and
the suffix.

Our immediate problem is to see if this variable still exists. (Variable
structures can change drastically whenever we call \\{get\_x\_next}; users
aren't supposed to do this, but the fact that it is possible means that
we must be cautious.) If the variable does exist, we also need to check
for a few other special cases before deciding that a plain old ordinary
variable has, indeed, been scanned.

\Y\P$\4\X706:Handle unusual cases that masquerade as variables, and \&{goto} %
\\{restart} or \&{return} if appropriate\X\S$\6
\&{if} $\\{post\_head}\I\\{null}$ \1\&{then}\5
\X708:Set up suffixed macro call and \&{goto} \\{restart}\X;\2\6
$\|q\K\\{link}(\\{pre\_head})$;\5
$\\{free\_avail}(\\{pre\_head})$;\6
\&{if} $\\{cur\_cmd}=\\{assignment}$ \1\&{then}\6
\&{if} $\\{start\_of\_stmt}$ \1\&{then}\6
\&{begin} \37$\\{cur\_type}\K\\{token\_list}$;\5
$\\{cur\_exp}\K\|q$;\6
\&{end};\2\2\6
$\|p\K\\{find\_variable}(\|q)$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Variable\ "})$;\5
$\\{show\_token\_list}(\|q,\39\\{null},\391000)$;\5
$\\{print}(\.{"\ has\ been\ obliterated"})$;\5
$\\{help5}(\.{"It\ seems\ you\ did\ a\ nasty\ thing---probably\ by\
accident,"})$\6
$(\.{"but\ nevertheless\ you\ nearly\ hornswoggled\ me..."})$\6
$(\.{"While\ I\ was\ evaluating\ the\ suffix\ of\ this\ variable,"})$\6
$(\.{"something\ was\ redefined,\ and\ it\'s\ no\ longer\ a\ variable!"})$\6
$(\.{"In\ order\ to\ get\ back\ on\ my\ feet,\ I\'ve\ inserted\ \`0\'\
instead."})$;\5
$\\{flush\_node\_list}(\|q)$;\5
\\{back\_input};\5
$\\{cur\_cmd}\K\\{numeric\_token}$;\5
$\\{cur\_mod}\K0$;\5
$\\{cur\_sym}\K0$;\5
\\{ins\_err};\5
\&{goto} \37\\{restart};\6
\&{end}\2\par
\U section~699.\fi

\M707. The only complication associated with macro calling is that the prefix
and ``at'' parameters must be packaged in an appropriate list of lists.

\Y\P$\4\X707:Set up unsuffixed macro call and \&{goto} \\{restart}\X\S$\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\\{pre\_head})\K\\{link}(\\{pre\_head})$;\5
$\\{link}(\\{pre\_head})\K\|p$;\5
$\\{info}(\|p)\K\|t$;\5
$\\{macro\_call}(\\{value}(\|q),\39\\{pre\_head},\39\\{null})$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~699.\fi

\M708. If the ``variable'' that turned out to be a suffixed macro no longer
exists,
we don't care, because we have reserved a pointer (\\{macro\_ref}) to its
token list.

\Y\P$\4\X708:Set up suffixed macro call and \&{goto} \\{restart}\X\S$\6
\&{begin} \37\\{back\_input};\5
$\|p\K\\{get\_avail}$;\5
$\|q\K\\{link}(\\{post\_head})$;\5
$\\{info}(\\{pre\_head})\K\\{link}(\\{pre\_head})$;\5
$\\{link}(\\{pre\_head})\K\\{post\_head}$;\5
$\\{info}(\\{post\_head})\K\|q$;\5
$\\{link}(\\{post\_head})\K\|p$;\5
$\\{info}(\|p)\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\\{null}$;\5
$\\{macro\_call}(\\{macro\_ref},\39\\{pre\_head},\39\\{null})$;\5
$\\{decr}(\\{ref\_count}(\\{macro\_ref}))$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~706.\fi

\M709. \P$\X709:Make a parameter act like a variable; \&{goto} \\{found} or %
\&{return} as appropriate\X\S$\6
\&{begin} \37$\|c\K\\{cur\_cmd}$;\5
$\|p\K\\{cur\_mod}$;\5
$\|q\K\\{cur\_sym}$;\5
\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}=\\{assignment}$ \1\&{then}\6
\&{if} $\\{start\_of\_stmt}$ \1\&{then}\6
\&{if} $\|c=\\{internal}$ \1\&{then}\6
\&{begin} \37$\\{cur\_type}\K\\{token\_list}$;\5
$\\{cur\_exp}\K\\{get\_avail}$;\5
$\\{info}(\\{cur\_exp})\K\|q$;\5
\&{return};\6
\&{end};\2\2\2\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~699.\fi

\M710. When and if a variable has been \\{found}, its two-word value packet
is designated by~\|p. Our remaining job is simply to make a copy of that
value. Some cases are harder than others, but complexity arises solely
because of the multiplicity of possible cases.

\Y\P$\4\X710:Copy the variable's value into $(\\{cur\_type},\\{cur\_exp})$ and %
\&{return}\X\S$\6
$\\{make\_exp\_copy}(\|p)$;\5
\&{return}\par
\U section~699.\fi

\M711. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\X712:Declare subroutines needed by \\{make\_exp\_copy}\X\6
\4\&{procedure}\1\  \37$\\{make\_exp\_copy}(\|p:\\{pointer})$;\2\6
\&{begin} \37$\\{cur\_type}\K\\{type}(\|p)$;\6
\&{case} $\\{cur\_type}$ \1\&{of}\6
\4$\\{boolean\_type},\39\\{known}$: \37$\\{cur\_exp}\K\\{value}(\|p)$;\6
\4$\\{unknown\_boolean},\39\\{unknown\_string},\39\\{unknown\_pen},\39%
\\{unknown\_edges},\39\\{unknown\_path}$: \37$\\{cur\_exp}\K\\{new\_ring%
\_entry}(\|p)$;\6
\4\\{string\_type}: \37$\\{cur\_exp}\K\\{value}(\|p)$;\C{fixthis for reference
count too?}\6
\4\\{pen\_type}: \37\&{begin} \37$\\{cur\_exp}\K\\{value}(\|p)$;\5
$\\{incr}(\\{ref\_count}(\\{cur\_exp}))$;\6
\&{end};\6
\4\\{edges\_type}: \37$\\{cur\_exp}\K\\{copy\_edges}(\\{value}(\|p))$;\6
\4$\\{path\_type},\39\\{future\_pen}$: \37$\\{cur\_exp}\K\\{copy\_path}(%
\\{value}(\|p))$;\6
\4\\{transform\_type}: \37$\\{copy\_big\_node}(\|p,\39\\{transform\_node%
\_size})$;\6
\4\\{pair\_type}: \37$\\{copy\_big\_node}(\|p,\39\\{pair\_node\_size})$;\6
\4$\\{dependent},\39\\{proto\_dependent}$: \37$\\{copy\_dep\_list}(\\{dep%
\_list}(\|p),\39\\{cur\_type})$;\6
\4\\{numeric\_type}: \37\&{begin} \37$\\{type}(\|p)\K\\{independent}$;\5
$\\{value}(\|p)\K0$;\5
$\\{cur\_type}\K\\{dependent}$;\5
$\\{cur\_exp}\K\\{single\_dependency}(\|p)$;\6
\&{end};\6
\4\\{independent}: \37\&{begin} \37$\\{cur\_type}\K\\{dependent}$;\5
$\\{cur\_exp}\K\\{single\_dependency}(\|p)$;\6
\&{end};\2\6
\&{end};\C{there should be no other cases}\6
\&{end};\par
\fi

\M712. When we copy an \\{independent} variable, the copy is \\{dependent};
it has a simple dependency list of length one.

\Y\P$\4\X712:Declare subroutines needed by \\{make\_exp\_copy}\X\S$\6
\4\&{function}\1\  \37$\\{single\_dependency}(\|p:\\{pointer})$: \37%
\\{pointer};\6
\4\&{var} \37\|q: \37\\{pointer};\C{the new dependency list}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{dep\_node\_size})$;\5
$\\{value}(\|q)\K\\{fraction\_one}$;\5
$\\{info}(\|q)\K\|p$;\6
$\\{dep\_tail}\K\\{get\_node}(\\{dep\_node\_size})$;\5
$\\{value}(\\{dep\_tail})\K0$;\5
$\\{info}(\\{dep\_tail})\K\\{null}$;\6
$\\{link}(\|q)\K\\{dep\_tail}$;\5
$\\{single\_dependency}\K\|q$;\6
\&{end};\par
\A sections~713 and~715.
\U section~711.\fi

\M713. \P$\X712:Declare subroutines needed by \\{make\_exp\_copy}\X\mathrel{+}%
\S$\6
\4\&{function}\1\  \37$\\{copy\_dep\_list}(\|p:\\{pointer})$: \37\\{pointer};\6
\4\&{var} \37\|q: \37\\{pointer};\C{the new dependency list}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{dep\_node\_size})$;\5
$\\{dep\_tail}\K\|q$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{info}(\\{dep\_tail})\K\\{info}(\|p)$;\5
$\\{value}(\\{dep\_tail})\K\\{value}(\|p)$;\6
\&{if} $\\{info}(\\{dep\_tail})=\\{null}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{link}(\\{dep\_tail})\K\\{get\_node}(\\{dep\_node\_size})$;\5
$\\{dep\_tail}\K\\{link}(\\{dep\_tail})$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{done}: \37$\\{copy\_dep\_list}\K\|q$;\6
\&{end};\par
\fi

\M714. The most tedious case arises when the user refers to a
\&{pair} or \&{transform} variable; we must copy several fields,
each of which can be \\{independent}, \\{dependent}, \\{proto\_dependent},
or \\{known}.

\fi

\M715. \P$\X712:Declare subroutines needed by \\{make\_exp\_copy}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37$\\{copy\_big\_node}(\|p:\\{pointer};\,\35\|s:\\{small%
\_number})$;\6
\4\&{var} \37$\|q,\39\|r,\39\|t$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37\&{if} $\\{value}(\|p)=\\{null}$ \1\&{then}\5
$\\{init\_big\_node}(\|p,\39\|s)$;\2\6
$\|t\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{name\_type}(\|t)\K\\{capsule}$;\5
$\\{type}(\|t)\K\\{cur\_type}$;\5
$\\{init\_big\_node}(\|t,\39\|s)$;\5
$\|q\K\\{value}(\|p)+\|s$;\5
$\|r\K\\{value}(\|t)+\|s$;\6
\1\&{repeat} \37$\|q\K\|q-2$;\5
$\|r\K\|r-2$;\6
\&{if} $\\{type}(\|q)=\\{known}$ \1\&{then}\6
\&{begin} \37$\\{value}(\|r)\K\\{value}(\|q)$;\5
$\\{type}(\|r)\K\\{known}$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{type}(\|q)=\\{independent}$ \1\&{then}\6
\&{begin} \37$\\{type}(\|r)\K\\{dependent}$;\5
$\\{dep\_list}(\|r)\K\\{single\_dependency}(\|q)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{type}(\|r)\K\\{type}(\|q)$;\5
$\\{dep\_list}(\|r)\K\\{copy\_dep\_list}(\|q)$;\6
\&{end};\2\6
$\\{link}(\\{dep\_tail})\K\\{link}(\\{dep\_head})$;\5
$\\{prev\_dep}(\\{link}(\\{dep\_head}))\K\|r$;\5
$\\{link}(\\{dep\_head})\K\|r$;\5
$\\{prev\_dep}(\|r)\K\\{dep\_head}$;\6
\&{end};\2\6
\4\&{until}\5
$\|q=\|p$;\2\6
$\\{copy\_big\_node}\K\|r$;\6
\&{end};\par
\fi

\M716. Here is a comparatively simple routine that is used to scan the
\&{suffix} parameters of a macro.

\Y\P\4\&{procedure}\1\  \37\\{scan\_suffix};\6
\4\&{var} \37$\|h,\39\|t$: \37\\{pointer};\C{head and tail of the list being
built}\2\6
\&{begin} \37$\|h\K\\{get\_avail}$;\5
$\|t\K\|h$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{cur\_cmd}=\\{left\_bracket}$ \1\&{then}\5
\X717:Scan a bracketed subscript and set $\\{cur\_cmd}\K\\{numeric\_token}$\X;%
\2\6
\&{if} $\\{cur\_cmd}=\\{numeric\_token}$ \1\&{then}\5
$\|p\K\\{new\_num\_tok}(\\{cur\_mod})$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{name\_token}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cur\_sym}$;\6
\&{end}\6
\4\&{else} \&{goto} \37\\{done};\2\2\6
$\\{link}(\|t)\K\|p$;\5
$\|t\K\|p$;\5
\\{get\_x\_next};\6
\&{end};\2\6
\4\\{done}: \37$\\{cur\_exp}\K\\{link}(\|h)$;\5
$\\{free\_avail}(\|h)$;\5
$\\{cur\_type}\K\\{token\_list}$;\6
\&{end};\par
\fi

\M717. \P$\X717:Scan a bracketed subscript and set $\\{cur\_cmd}\K\\{numeric%
\_token}$\X\S$\6
\&{begin} \37\\{get\_x\_next};\5
\\{scan\_expression};\6
\&{if} $\\{cur\_type}\I\\{known}$ \1\&{then}\5
\\{bad\_subscript};\2\6
\&{if} $\\{cur\_cmd}=\\{right\_brackt}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`]\'\ inserted"})$;\5
$\\{help3}(\.{"I\'ve\ seen\ a\ \`[\'\ and\ a\ subscript\ value,\ in\ a\
suffix,"})$\6
$(\.{"so\ a\ right\ bracket\ should\ have\ come\ next."})$\6
$(\.{"I\ shall\ pretend\ that\ one\ was\ there."})$\5
\\{back\_error};\6
\&{end};\2\6
$\\{cur\_cmd}\K\\{numeric\_token}$;\5
$\\{cur\_mod}\K\\{cur\_exp}$;\6
\&{end}\par
\U section~716.\fi

\N718.  \[xx] Parsing secondary and higher expressions.
After the complications of \\{scan\_primary}, the \\{scan\_secondary} routine
is refreshingly simple. It's not trivial, but it's relatively straightforward;
the main difficulty is, again, that expressions and data structures might
change drastically every time we call \\{get\_x\_next}, so a cautious approach
is mandatory. For example, a macro defined by \&{primarydef} might have
disappeared by the time its second argument has been scanned; so we
must make sure that its token list stays around, by increasing its
reference count.

\Y\P\4\&{procedure}\1\  \37\\{scan\_secondary};\6
\4\&{label} \37$\\{restart},\39\\{continue},\39\\{exit}$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\6
$\|c,\39\|d$: \37\\{halfword};\C{operation codes or modifiers}\6
\\{mac\_name}: \37\\{pointer};\C{token defined with \&{primarydef}}\2\6
\&{begin} \37\\{restart}: \37\&{if} $(\\{cur\_cmd}<\\{min\_primary\_command})\V%
\30(\\{cur\_cmd}>\\{max\_primary\_command})$ \1\&{then}\5
$\\{bad\_exp}(\.{"A\ secondary"})$;\2\6
\\{scan\_primary};\6
\4\\{continue}: \37\&{if} $\\{cur\_cmd}\G\\{min\_secondary\_command}$ \1%
\&{then}\6
\&{if} $\\{cur\_cmd}\L\\{max\_secondary\_command}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{stash\_temp}$;\5
$\|c\K\\{cur\_mod}$;\5
$\|d\K\\{cur\_cmd}$;\6
\&{if} $\|d=\\{secondary\_primary\_macro}$ \1\&{then}\6
\&{begin} \37$\\{mac\_name}\K\\{cur\_sym}$;\5
$\\{add\_ref}(\|c)$;\6
\&{end};\2\6
\\{get\_x\_next};\6
\&{if} $\|d=\\{left\_bracket}$ \1\&{then}\5
\X721:Scan a mediation construction\X\6
\4\&{else} \&{begin} \37\\{scan\_primary};\6
\&{if} $\|d\I\\{secondary\_primary\_macro}$ \1\&{then}\5
$\\{do\_binary}(\|p,\39\|c)$\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{binary\_mac}(\|p,\39\|c,\39\\{mac\_name})$;\5
$\\{decr}(\\{ref\_count}(\|c))$;\5
\\{get\_x\_next};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\2\6
\&{goto} \37\\{continue};\6
\&{end};\2\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M719. The following procedure calls a macro that has two parameters,
\|p and \\{cur\_exp}.

\fi

\M720. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37$\\{binary\_mac}(\|p,\39\|c,\39\|n:\\{pointer})$;\6
\4\&{var} \37$\|q,\39\|r$: \37\\{pointer};\C{nodes in the parameter list}\2\6
\&{begin} \37$\|q\K\\{get\_avail}$;\5
$\|r\K\\{get\_avail}$;\5
$\\{link}(\|q)\K\|r$;\6
$\\{info}(\|q)\K\|p$;\5
$\\{info}(\|r)\K\\{stash\_cur\_exp}$;\6
$\\{macro\_call}(\|c,\39\|q,\39\|n)$;\6
\&{end};\par
\fi

\M721. Expressions of the form `\.{a[b,c]}' are converted into
`\.{b+a*(c-b)}', without checking the types of \.a, \.b, or \.c.

\Y\P$\4\X721:Scan a mediation construction\X\S$\6
\&{begin} \37\\{scan\_expression};\6
\&{if} $\\{cur\_cmd}\I\\{comma}$ \1\&{then}\6
\&{begin} \37\X701:Put the left bracket and the expression back to be rescanned%
\X;\6
\&{return};\6
\&{end};\2\6
$\|q\K\\{stash\_cur\_exp}$;\5
\\{get\_x\_next};\5
\\{get\_expression};\6
\&{if} $\\{cur\_cmd}\I\\{right\_bracket}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`]\'\ inserted"})$;\5
$\\{help3}(\.{"I\'ve\ scanned\ an\ expression\ of\ the\ form\ \`a[b,c\',"})$\6
$(\.{"so\ a\ right\ bracket\ should\ have\ come\ next."})$\6
$(\.{"I\ shall\ pretend\ that\ one\ was\ there."})$\5
\\{back\_error};\6
\&{end};\2\6
$\|r\K\\{stash\_cur\_exp}$;\5
$\\{make\_exp\_copy}(\|q)$;\6
$\\{do\_binary}(\|r,\39\\{minus})$;\5
$\\{do\_binary}(\|p,\39\\{times})$;\5
$\\{do\_binary}(\|q,\39\\{plus})$;\5
\\{get\_x\_next};\6
\&{end}\par
\U section~718.\fi

\M722. The next procedure, \\{scan\_tertiary}, is pretty much the same deal.
Braces (rather than brackets) keep this level from being entirely
devoid of interest.

\Y\P\4\&{procedure}\1\  \37\\{scan\_tertiary};\6
\4\&{label} \37$\\{restart},\39\\{continue}$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\6
$\|c,\39\|d$: \37\\{halfword};\C{operation codes or modifiers}\6
\\{mac\_name}: \37\\{pointer};\C{token defined with \&{secondarydef}}\2\6
\&{begin} \37\\{restart}: \37\&{if} $(\\{cur\_cmd}<\\{min\_primary\_command})\V%
\30(\\{cur\_cmd}>\\{max\_primary\_command})$ \1\&{then}\5
$\\{bad\_exp}(\.{"A\ tertiary"})$;\2\6
\\{scan\_secondary};\6
\&{if} $\\{cur\_type}=\\{future\_pen}$ \1\&{then}\5
\\{materialize\_pen};\2\6
\4\\{continue}: \37\&{if} $\\{cur\_cmd}\G\\{min\_tertiary\_command}$ \1\&{then}%
\6
\&{if} $\\{cur\_cmd}\L\\{max\_tertiary\_command}$ \1\&{then}\6
\&{if} $(\\{cur\_cmd}\I\\{ampersand})\V(\\{cur\_type}<\\{path\_type})$ \1%
\&{then}\6
\&{begin} \37$\|p\K\\{stash\_temp}$;\5
$\|c\K\\{cur\_mod}$;\5
$\|d\K\\{cur\_cmd}$;\6
\&{if} $\|d=\\{tertiary\_secondary\_macro}$ \1\&{then}\6
\&{begin} \37$\\{mac\_name}\K\\{cur\_sym}$;\5
$\\{add\_ref}(\|c)$;\6
\&{end};\2\6
\\{get\_x\_next};\6
\&{if} $\|d=\\{left\_brace}$ \1\&{then}\5
\X724:Scan a direction specification\X\6
\4\&{else} \&{begin} \37\\{scan\_secondary};\6
\&{if} $\|d\I\\{tertiary\_secondary\_macro}$ \1\&{then}\5
$\\{do\_binary}(\|p,\39\|c)$\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{binary\_mac}(\|p,\39\|c,\39\\{mac\_name})$;\5
$\\{decr}(\\{ref\_count}(\|c))$;\5
\\{get\_x\_next};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\2\6
\&{goto} \37\\{continue};\6
\&{end};\2\2\2\6
\&{end};\par
\fi

\M723. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{materialize\_pen};\C{changes a \\{future\_pen} to an
actual pen}\2\6
\&{begin} \37\\{do\_nothing};\C{I haven't implemented the stuff that generates
future pens yet!}\6
\&{end};\par
\fi

\M724. There's nothing difficult about scanning a direction specification,
but the program is rather lengthy because a variety of potential
errors need to be nipped in the bud.

\Y\P$\4\X724:Scan a direction specification\X\S$\6
\&{begin} \37\X725:Move the coordinates from \|p to a new ``fragment'' node \|q%
\X;\6
\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}=\\{curl\_command}$ \1\&{then}\5
\X730:Put a curl specification into fragment \|q\X\6
\4\&{else} \X731:Put a given direction into fragment \|q\X;\2\6
\&{if} $\\{cur\_cmd}\I\\{right\_brace}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`\}\'\ inserted"})$;\5
$\\{help3}(\.{"I\'ve\ scanned\ a\ direction\ spec\ for\ part\ of\ a\ path,"})$\6
$(\.{"so\ a\ right\ brace\ should\ have\ come\ next."})$\6
$(\.{"I\ shall\ pretend\ that\ one\ was\ there."})$\5
\\{back\_error};\6
\&{end};\2\6
$\\{cur\_type}\K\\{path\_type}$;\5
$\\{cur\_exp}\K\|q$;\5
\\{get\_x\_next};\5
\X733:Change a given direction of $(0,0)$ back to a simple pair\X;\6
\&{end}\par
\U section~722.\fi

\M725. \P$\X725:Move the coordinates from \|p to a new ``fragment'' node \|q\X%
\S$\6
\&{begin} \37$\\{unstash\_cur\_exp}(\|p)$;\5
$\|q\K\\{new\_fragment}$;\6
\&{end}\par
\U section~724.\fi

\M726. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\X728:Declare the function called \\{known\_pair}\X\6
\4\&{function}\1\  \37\\{new\_fragment};\C{convert a pair to a fragment of type
\\{open}}\6
\4\&{var} \37\|q: \37\\{pointer};\C{the fragment node}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{knot\_node\_size})$;\5
$\\{left\_type}(\|q)\K\\{fragment}$;\5
$\\{right\_type}(\|q)\K\\{open}$;\5
$\\{right\_curl}(\|q)\K\\{unity}$;\5
$\|p\K\\{known\_pair}$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{x\_coord}(\|q)\K0$;\5
$\\{y\_coord}(\|q)\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{x\_coord}(\|q)\K\\{value}(\\{x\_part\_loc}(\|p))$;\5
$\\{y\_coord}(\|q)\K\\{value}(\\{y\_part\_loc}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{pair\_node\_size})$;\6
\&{end};\2\6
$\\{new\_fragment}\K\|q$;\6
\&{end};\par
\fi

\M727. If the current expression is not a pair type, the
\\{known\_pair} subroutine returns \\{null} (after reporting an error).
Otherwise a pair node containing two \\{known} values is returned.
In all cases the current expression is effectively flushed.

\fi

\M728. \P$\X728:Declare the function called \\{known\_pair}\X\S$\6
\4\&{function}\1\  \37\\{known\_pair}: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the pair node}\2\6
\&{begin} \37\&{if} $\\{cur\_type}\I\\{pair}$ \1\&{then}\6
\&{begin} \37$\\{exp\_err}(\.{"Undefined\ coordinates\ will\ be\ replaced\ by\
(0,0)"})$;\5
$\\{help3}(\.{"I\ need\ x\ and\ y\ numbers\ for\ this\ part\ of\ the\ path."})$%
\6
$(\.{"The\ value\ I\ found\ (see\ above)\ was\ no\ good;"})$\6
$(\.{"so\ I\'ll\ try\ to\ keep\ going\ by\ using\ zero\ instead."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(0)$;\5
$\\{known\_pair}\K\\{null}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\5
$\\{free\_node}(\\{cur\_exp},\39\\{value\_node\_size})$;\6
\X729:Make sure that both \|x and \|y parts of \|p are known\X;\6
$\\{cur\_type}\K\\{vacuous}$;\5
$\\{known\_pair}\K\|p$;\6
\&{end};\2\6
\&{end};\par
\U section~726.\fi

\M729. \P$\X729:Make sure that both \|x and \|y parts of \|p are known\X\S$\6
\&{if} $\\{type}(\\{x\_part\_loc}(\|p))\I\\{known}$ \1\&{then}\6
\&{begin} \37$\\{disp\_err}(\\{x\_part\_loc}(\|p),\39\.{"Undefined\ x\
coordinate\ has\ been\ replaced\ by\ 0"})$;\5
$\\{help3}(\.{"I\ need\ a\ \`known\'\ x\ value\ for\ this\ part\ of\ the\
path."})$\6
$(\.{"The\ value\ I\ found\ (see\ above)\ was\ no\ good;"})$\6
$(\.{"so\ I\'ll\ try\ to\ keep\ going\ by\ using\ zero\ instead."})$;\5
\\{error};\5
$\\{recycle\_value}(\\{x\_part\_loc}(\|p))$;\5
$\\{type}(\\{x\_part\_loc}(\|p))\K\\{known}$;\5
$\\{value}(\\{x\_part\_loc}(\|p))\K0$;\6
\&{end};\2\6
\&{if} $\\{type}(\\{y\_part\_loc}(\|p))\I\\{known}$ \1\&{then}\6
\&{begin} \37$\\{disp\_err}(\\{y\_part\_loc}(\|p),\39\.{"Undefined\ y\
coordinate\ has\ been\ replaced\ by\ 0"})$;\5
$\\{help3}(\.{"I\ need\ a\ \`known\'\ y\ value\ for\ this\ part\ of\ the\
path."})$\6
$(\.{"The\ value\ I\ found\ (see\ above)\ was\ no\ good;"})$\6
$(\.{"so\ I\'ll\ try\ to\ keep\ going\ by\ using\ zero\ instead."})$;\5
\\{error};\5
$\\{recycle\_value}(\\{y\_part\_loc}(\|p))$;\5
$\\{type}(\\{y\_part\_loc}(\|p))\K\\{known}$;\5
$\\{value}(\\{y\_part\_loc}(\|p))\K0$;\6
\&{end}\2\par
\U section~728.\fi

\M730. \P$\X730:Put a curl specification into fragment \|q\X\S$\6
\&{begin} \37\\{get\_x\_next};\5
\\{scan\_expression};\6
\&{if} $(\\{cur\_type}\I\\{known})\V(\\{cur\_exp}<0)$ \1\&{then}\6
\&{begin} \37$\\{exp\_err}(\.{"Improper\ curl\ has\ been\ replaced\ by\ 1"})$;\5
$\\{help1}(\.{"A\ curl\ must\ be\ a\ known,\ nonnegative\ number."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(\\{unity})$;\6
\&{end};\2\6
$\\{right\_type}(\|q)\K\\{curl}$;\5
$\\{right\_curl}(\|q)\K\\{cur\_exp}$;\6
\&{end}\par
\U section~724.\fi

\M731. \P$\X731:Put a given direction into fragment \|q\X\S$\6
\&{begin} \37$\\{right\_type}(\|q)\K\\{given}$;\5
\\{scan\_expression};\6
\&{if} $\\{cur\_type}>\\{pair\_type}$ \1\&{then}\5
\X732:Get given directions separated by commas\X\6
\4\&{else} \&{begin} \37$\|p\K\\{known\_pair}$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{right\_x}(\|q)\K0$;\5
$\\{right\_y}(\|q)\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{right\_x}(\|q)\K\\{value}(\\{x\_part\_loc}(\|p))$;\5
$\\{right\_y}(\|q)\K\\{value}(\\{y\_part\_loc}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{pair\_node\_size})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~724.\fi

\M732. \P$\X732:Get given directions separated by commas\X\S$\6
\&{begin} \37\&{if} $\\{cur\_type}\I\\{known}$ \1\&{then}\6
\&{begin} \37$\\{exp\_err}(\.{"Undefined\ x\ coordinate\ has\ been\ replaced\
by\ 0"})$;\5
$\\{help3}(\.{"I\ need\ a\ \`known\'\ x\ value\ for\ this\ part\ of\ the\
path."})$\6
$(\.{"The\ value\ I\ found\ (see\ above)\ was\ no\ good;"})$\6
$(\.{"so\ I\'ll\ try\ to\ keep\ going\ by\ using\ zero\ instead."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(0)$;\6
\&{end};\2\6
$\\{right\_x}(\|q)\K\\{cur\_exp}$;\6
\&{if} $\\{cur\_cmd}\I\\{comma}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`,\'\ inserted"})$;\5
$\\{help2}(\.{"I\'ve\ got\ the\ x\ coordinate\ of\ a\ path\ direction;"})$\6
$(\.{"will\ look\ for\ the\ y\ coordinate\ next."})$;\5
\\{back\_error};\6
\&{end};\2\6
\\{get\_x\_next};\5
\\{scan\_expression};\6
\&{if} $\\{cur\_type}\I\\{known}$ \1\&{then}\6
\&{begin} \37$\\{exp\_err}(\.{"Undefined\ y\ coordinate\ has\ been\ replaced\
by\ 0"})$;\5
$\\{help3}(\.{"I\ need\ a\ \`known\'\ y\ value\ for\ this\ part\ of\ the\
path."})$\6
$(\.{"The\ value\ I\ found\ (see\ above)\ was\ no\ good;"})$\6
$(\.{"so\ I\'ll\ try\ to\ keep\ going\ by\ using\ zero\ instead."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(0)$;\6
\&{end};\2\6
$\\{right\_y}(\|q)\K\\{cur\_exp}$;\6
\&{end}\par
\U section~731.\fi

\M733. When the user gives a null direction, the `\.{\{0,0\}}' is silently
ignored. FIXTHIS: the present module can be removed; can do it better below.

\Y\P$\4\X733:Change a given direction of $(0,0)$ back to a simple pair\X\S$\6
\&{if} $\\{right\_type}(\|q)=\\{given}$ \1\&{then}\6
\&{if} $\\{right\_x}(\|q)=0$ \1\&{then}\6
\&{if} $\\{right\_y}(\|q)=0$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_node}(\\{value\_node\_size})$;\5
$\\{type}(\|p)\K\\{pair\_type}$;\5
$\\{name\_type}(\|p)\K\\{capsule}$;\5
$\\{init\_big\_node}(\|p,\39\\{pair\_node\_size})$;\5
$\\{cur\_exp}\K\|p$;\5
$\\{cur\_type}\K\\{pair\_type}$;\5
$\|p\K\\{value}(\|p)$;\6
$\\{type}(\\{x\_part\_loc}(\|p))\K\\{known}$;\5
$\\{value}(\\{x\_part\_loc}(\|p))\K\\{x\_coord}(\|q)$;\5
$\\{type}(\\{y\_part\_loc}(\|p))\K\\{known}$;\5
$\\{value}(\\{y\_part\_loc}(\|p))\K\\{y\_coord}(\|q)$;\5
$\\{free\_node}(\|q,\39\\{knot\_node\_size})$;\6
\&{end}\2\2\2\par
\U section~724.\fi

\M734. Finally we reach the deepest level in our quartet of parsing routines.
This one is much like the others; it has an extra complication from
the construction of paths, which materialize here.

\Y\P\4\&{procedure}\1\  \37\\{scan\_expression};\6
\4\&{label} \37$\\{restart},\39\\{continue},\39\\{exit}$;\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\6
$\|c,\39\|d$: \37\\{halfword};\C{operation codes or modifiers}\6
\\{start\_of\_stmt}: \37\\{boolean};\C{initial value of \\{beginning}}\6
\\{mac\_name}: \37\\{pointer};\C{token defined with \&{tertiarydef}}\2\6
\&{begin} \37$\\{start\_of\_stmt}\K\\{beginning}$;\6
\4\\{restart}: \37\&{if} $(\\{cur\_cmd}<\\{min\_primary\_command})\V\30(\\{cur%
\_cmd}>\\{max\_primary\_command})$ \1\&{then}\5
$\\{bad\_exp}(\.{"An"})$;\2\6
\\{scan\_tertiary};\6
\4\\{continue}: \37\&{if} $\\{cur\_cmd}\G\\{min\_expression\_command}$ \1%
\&{then}\6
\&{if} $\\{cur\_cmd}\L\\{max\_expression\_command}$ \1\&{then}\6
\&{if} $(\\{cur\_cmd}\I\\{equals})\V\R\\{start\_of\_stmt}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{stash\_temp}$;\5
$\|c\K\\{cur\_mod}$;\5
$\|d\K\\{cur\_cmd}$;\6
\&{if} $\|d=\\{expression\_tertiary\_macro}$ \1\&{then}\6
\&{begin} \37$\\{mac\_name}\K\\{cur}\K\\{sym}$;\5
$\\{add\_ref}(\|c)$;\6
\&{end};\2\6
\&{if} $\|d\L\\{path\_join}$ \1\&{then}\5
\X735:Scan a path construction operation\X\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\5
\\{scan\_tertiary};\6
\&{if} $\|d\I\\{expression\_tertiary\_macro}$ \1\&{then}\5
$\\{do\_binary}(\|p,\39\|c)$\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{binary\_mac}(\|p,\39\|c,\39\\{mac\_name})$;\5
$\\{decr}(\\{ref\_count}(\|c))$;\5
\\{get\_x\_next};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\2\6
\&{goto} \37\\{continue};\6
\&{end};\2\2\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M735. The reader should review the data structure conventions for paths before
hoping to understand the next part of this code.

We piece together a path from operands that are pairs, fragments, or paths.
Pairs come from nodes with no given direction or curl; fragments are
stamped with an explicit direction or curl; paths are entire lists of knots
that are spliced in.

\Y\P$\4\X735:Scan a path construction operation\X\S$\6
\&{begin} \37\X736:Convert the left operand, \|p, into a partial path ending
at~\|q; but set $\\{abort\_path}\K\\{true}$ if \|p doesn't have a suitable type%
\X;\6
\4\\{continue\_path}: \37$\|d\K\\{cur\_cmd}$;\6
\&{if} $\|d=\\{path\_join}$ \1\&{then}\5
\X738:Determine the path join parameters\X;\2\6
\\{get\_x\_next};\6
\&{if} $(\\{cur\_cmd}=\\{cycle})\W\R\\{abort\_path}$ \1\&{then}\5
\X745:Get ready to close a cycle\X\6
\4\&{else} \&{begin} \37$\\{cycle\_hit}\K\\{false}$;\5
\\{scan\_tertiary};\6
\&{if} $\\{abort\_path}$ \1\&{then}\C{evoke an error message consistent with
others in \MF}\6
\&{begin} \37$\\{do\_binary}(\|p,\39\|c)$;\5
\&{goto} \37\\{continue};\6
\&{end};\2\6
\X744:Convert the right operand, \\{cur\_exp}, into a partial path from \\{pp}
to~\\{qq}\X;\6
\&{end};\2\6
\X746:Join the partial paths and reset \|p and \|q to the head and tail of the
result\X;\6
\&{if} $\\{cur\_cmd}\G\\{min\_expression\_command}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}\L\\{path\_join}$ \1\&{then}\6
\&{if} $\R\\{cycle\_hit}$ \1\&{then}\5
\&{goto} \37\\{continue\_path};\2\2\2\6
\X748:Choose control points for the path and put the result into \\{cur\_exp}%
\X;\6
\&{end}\par
\U section~734.\fi

\M736. \P$\X736:Convert the left operand, \|p, into a partial path ending at~%
\|q; but set $\\{abort\_path}\K\\{true}$ if \|p doesn't have a suitable type\X%
\S$\6
\&{begin} \37$\\{abort\_path}\K\\{false}$;\5
$\\{given\_list}\K\\{null}$;\6
\&{if} $\\{type}(\|p)=\\{pair\_type}$ \1\&{then}\6
\&{begin} \37$\\{unstash\_cur\_exp}(\|p)$;\5
$\|p\K\\{new\_fragment}$;\6
\&{end}\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{path\_type}$ \1\&{then}\5
$\|p\K\\{value}(\|p)$\6
\4\&{else} \&{begin} \37$\\{abort\_path}\K\\{true}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\2\6
$\|q\K\|p$;\6
\&{if} $\\{left\_type}(\|p)=\\{fragment}$ \1\&{then}\5
$\\{fix\_fragment}(\|p)$\6
\4\&{else} \&{begin} \37$\\{left\_type}(\|p)\K\\{end\_point}$;\C{if \|p was a
cycle, it is broken}\6
\&{while} $\\{left\_type}(\\{link}(\|q))\I\\{end\_point}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{right\_type}(\|q)\K\\{endpoint}$;\6
\&{end};\2\6
\4\\{done}: \37\&{end}\par
\U section~735.\fi

\M737. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37$\\{fix\_fragment}(\|p:\\{pointer})$;\2\6
\&{begin} \37\&{if} $\\{right\_type}(\|p)=\\{given}$ \1\&{then}\6
\&{if} $(\\{right\_x}(\|p)=0)\W(\\{right\_y}(\|p)=0)$ \1\&{then}\6
\&{begin} \37$\\{right\_type}(\|p)\K\\{open}$;\5
$\\{right\_curl}(\|p)\K\\{unity}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|r\K\\{get\_node}(\\{coord\_node\_size})$;\5
$\\{x\_coord}(\|r)\K\\{right\_x}(\|p)$;\5
$\\{y\_coord}(\|r)\K\\{right\_y}(\|p)$;\5
$\\{link}(\|r)\K\\{given\_list}$;\5
$\\{given\_list}\K\|r$;\5
$\\{right\_given}(\|p)\K\|r$;\6
\&{end};\2\2\6
$\\{left\_type}(\|p)\K\\{right\_type}(\|p)$;\5
$\\{left\_curl}(\|p)\K\\{right\_curl}(\|p)$;\C{note that $\\{left\_given}\S%
\\{left\_curl}$}\6
\&{end};\par
\fi

\M738. \P$\X738:Determine the path join parameters\X\S$\6
\&{begin} \37\\{get\_x\_next};\6
\&{if} $\\{cur\_cmd}=\\{tension}$ \1\&{then}\5
\X741:Set explicit tensions\X\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{controls}$ \1\&{then}\5
\X743:Set explicit control points\X\6
\4\&{else} \&{begin} \37$\\{right\_tension}(\|q)\K\\{unity}$;\5
$\|t\K\\{unity}$;\5
\\{back\_input};\C{default tension}\6
\&{goto} \37\\{done1};\6
\&{end};\2\2\6
\4\\{common\_ending}: \37\&{if} $\\{cur\_cmd}\I\\{path\_join}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`..\'\ inserted"})$;\5
$\\{help1}(\.{"A\ path\ join\ command\ should\ end\ with\ two\ dots."})$;\5
\\{back\_error};\6
\&{end};\2\6
\4\\{done1}: \37\&{end}\par
\U section~735.\fi

\M739. The `\&{bounded}' option is a special case of `\&{tension}', represented
internally by tension values of zero.

\Y\P\D \37$\\{tension\_code}=1$\par
\P\D \37$\\{bounded\_code}=0$\par
\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"tension"},\39\\{tension},\39\\{tension\_code})$;\6
$\\{primitive}(\.{"bounded"},\39\\{tension},\39\\{bounded\_code})$;\par
\fi

\M740. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{tension}: \37\&{if} $\mathbin{\&{mod}}=\\{bounded\_code}$ \1\&{then}\5
$\\{print}(\.{"bounded"})$\ \&{else} $\\{print}(\.{"tension"})$;\2\par
\fi

\M741. \P$\X741:Set explicit tensions\X\S$\6
\&{if} $\\{cur\_mod}=\\{bounded\_code}$ \1\&{then}\6
\&{begin} \37$\\{right\_tension}(\|q)\K0$;\5
$\|t\K0$;\5
\\{get\_x\_next};\6
\&{end}\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\5
\\{scan\_expression};\5
\X742:Make sure the current expression is a valid tension setting\X;\6
$\\{right\_tension}(\|q)\K\\{cur\_exp}$;\6
\&{if} $\\{cur\_cmd}\I\\{and\_command}$ \1\&{then}\5
$\|t\K\\{cur\_exp}$\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\5
\\{scan\_expression};\5
\X742:Make sure the current expression is a valid tension setting\X;\6
$\|t\K\\{cur\_exp}$;\6
\&{end};\2\6
\&{end}\2\par
\U section~738.\fi

\M742. \P$\X742:Make sure the current expression is a valid tension setting\X%
\S$\6
\&{if} $(\\{cur\_type}\I\\{known})\V(\\{cur\_exp}<\\{min\_tension})$ \1\&{then}%
\6
\&{begin} \37$\\{exp\_err}(\.{"Improper\ tension\ has\ been\ set\ to\ 1"})$;\5
$\\{help1}(\.{"The\ expression\ above\ should\ have\ been\ a\ number\ >\
.6667."})$;\5
\\{error};\5
$\\{flush\_cur\_exp}(\\{unity})$;\6
\&{end}\2\par
\U sections~741 and~741.\fi

\M743. \P$\X743:Set explicit control points\X\S$\6
\&{begin} \37$\\{right\_type}(\|q)\K\\{explicit}$;\5
\\{get\_x\_next};\5
\\{scan\_expression};\5
$\\{pp}\K\\{known\_pair}$;\6
\&{if} $\\{pp}=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{right\_x}(\|q)\K0$;\5
$\\{right\_y}(\|q)\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{right\_x}(\|q)\K\\{value}(\\{x\_part\_loc}(%
\\{pp}))$;\5
$\\{right\_y}(\|q)\K\\{value}(\\{y\_part\_loc}(\\{pp}))$;\5
$\\{free\_node}(\\{pp},\39\\{pair\_node\_size})$;\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}\I\\{and\_command}$ \1\&{then}\6
\&{begin} \37$\|x\K\\{right\_x}(\|q)$;\5
$\|y\K\\{right\_y}(\|q)$;\6
\&{end}\6
\4\&{else} \&{begin} \37\\{get\_x\_next};\5
\\{scan\_expression};\5
$\\{pp}\K\\{known\_pair}$;\6
\&{if} $\\{pp}=\\{null}$ \1\&{then}\6
\&{begin} \37$\|x\K0$;\5
$\|y\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|x\K\\{value}(\\{x\_part\_loc}(\\{pp}))$;\5
$\|y\K\\{value}(\\{y\_part\_loc}(\\{pp}))$;\5
$\\{free\_node}(\\{pp},\39\\{pair\_node\_size})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~738.\fi

\M744. \P$\X744:Convert the right operand, \\{cur\_exp}, into a partial path
from \\{pp} to~\\{qq}\X\S$\6
\&{begin} \37\&{if} $\\{cur\_type}\I\\{path\_type}$ \1\&{then}\5
$\\{pp}\K\\{new\_fragment}$\6
\4\&{else} $\\{pp}\K\\{cur\_exp}$;\2\6
$\\{qq}\K\\{pp}$;\6
\&{if} $\\{left\_type}(\\{pp})\I\\{fragment}$ \1\&{then}\5
$\\{fix\_fragment}(\\{pp})$\6
\4\&{else} \&{begin} \37$\\{left\_type}(\\{pp})\K\\{end\_point}$;\C{if \\{pp}
was a cycle, it is broken}\6
\&{while} $\\{left\_type}(\\{link}(\\{qq}))\I\\{end\_point}$ \1\&{do}\5
$\\{qq}\K\\{link}(\\{qq})$;\2\6
$\\{right\_type}(\\{qq})\K\\{endpoint}$;\6
\&{end};\2\6
\&{end}\par
\U section~735.\fi

\M745. If a person says `\.{(x,y)\&cycle}' we silently change it to
`\.{(x,y)..cycle}', since a path shouldn't have length $-1$.

\Y\P$\4\X745:Get ready to close a cycle\X\S$\6
\&{begin} \37$\\{cycle\_hit}\K\\{true}$;\5
$\\{pp}\K\|p$;\5
$\\{qq}\K\|p$;\6
\&{if} $\|d=\\{ampersand}$ \1\&{then}\6
\&{if} $\|p=\|q$ \1\&{then}\6
\&{begin} \37$\|d\K\\{path\_join}$;\5
$\\{right\_tension}(\|q)\K\\{unity}$;\5
$\|t\K\\{unity}$;\6
\&{end};\2\2\6
\&{end}\par
\U section~735.\fi

\M746. \P$\X746:Join the partial paths and reset \|p and \|q to the head and
tail of the result\X\S$\6
\&{begin} \37\&{if} $\|d=\\{ampersand}$ \1\&{then}\6
\&{if} $(\\{x\_coord}(\|q)\I\\{x\_coord}(\\{pp}))\V(\\{y\_coord}(\|q)\I\\{y%
\_coord}(\\{pp}))$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Paths\ don\'t\ touch;\ \`\&\'\ will\ be\
changed\ to\ \`..\'"})$;\5
$\\{help3}(\.{"When\ you\ join\ paths\ \`p\&q\',\ the\ ending\ point\ of\ p"})$%
\6
$(\.{"must\ be\ exactly\ equal\ to\ the\ starting\ point\ of\ q."})$\6
$(\.{"So\ I\'m\ going\ to\ pretend\ that\ you\ said\ \`p..q\'\ instead."})$;\5
\\{error};\5
$\|d\K\\{path\_join}$;\5
$\\{right\_tension}(\|q)\K\\{unity}$;\5
$\|t\K\\{unity}$;\6
\&{end};\2\2\6
\&{if} $\|d=\\{ampersand}$ \1\&{then}\5
\X747:Splice independent paths together\X\6
\4\&{else} \&{begin} \37$\\{link}(\|q)\K\\{pp}$;\6
\&{if} $\\{right\_type}(\|q)\I\\{explicit}$ \1\&{then}\5
$\\{left\_tension}(\\{pp})\K\|t$\6
\4\&{else} \&{begin} \37$\\{left\_x}(\\{pp})\K\|x$;\5
$\\{left\_y}(\\{pp})\K\|y$;\5
$\\{left\_type}(\\{pp})\K\\{explicit}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~735.\fi

\M747. \P$\X747:Splice independent paths together\X\S$\6
\&{begin} \37\&{if} $\\{left\_type}(\|q)=\\{open}$ \1\&{then}\5
$\\{left\_type}(\|q)\K\\{curl}$;\C{$\\{left\_curl}(\|q)=\\{unity}$}\2\6
\&{if} $\\{right\_type}(\\{pp})=\\{open}$ \1\&{then}\5
$\\{right\_type}(\\{pp})\K\\{curl}$;\C{$\\{right\_curl}(\\{pp})=\\{unity}$}\2\6
$\\{right\_type}(\|q)\K\\{right\_type}(\\{pp})$;\5
$\\{right\_x}(\|q)\K\\{right\_x}(\\{pp})$;\5
$\\{right\_y}(\|q)\K\\{right\_y}(\\{pp})$;\5
$\\{link}(\|q)\K\\{link}(\\{pp})$;\5
$\\{free\_node}(\\{pp},\39\\{knot\_node\_size})$;\6
\&{if} $\\{qq}=\\{pp}$ \1\&{then}\5
$\\{qq}\K\|q$;\2\6
\&{end}\par
\U section~746.\fi

\M748. \P$\X748:Choose control points for the path and put the result into %
\\{cur\_exp}\X\S$\6
\&{if} $\\{cycle\_hit}$ \1\&{then}\6
\&{begin} \37\&{if} $\|d=\\{ampersand}$ \1\&{then}\5
$\|p\K\|q$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{left\_type}(\|p)\K\\{endpoint}$;\6
\&{if} $\\{right\_type}(\|p)=\\{open}$ \1\&{then}\5
$\\{right\_type}(\|p)\K\\{curl}$;\2\6
$\\{right\_type}(\|q)\K\\{endpoint}$;\6
\&{if} $\\{left\_type}(\|q)=\\{open}$ \1\&{then}\5
$\\{left\_type}(\|q)\K\\{curl}$;\2\6
$\\{link}(\|q)\K\|p$;\6
\&{end};\2\6
$\\{make\_choices}(\|p,\39\\{given\_list})$;\5
$\\{cur\_type}\K\\{path\_type}$;\5
$\\{cur\_exp}\K\|p$ \6
\&{end} \par
\U section~735.\fi

\M749. \P$\X684:Declare subroutines needed for expression parsing\X\mathrel{+}%
\S$\par
\fi

\N750.  \[xx] Doing the operations.
The purpose of parsing is primarily to permit people to avoid piles of
parentheses. But the real work is done after the structure of an expression
has been recognized; that's when new expressions are generated. We
turn now to the guts of \MF, which handles individual operators that
have come through the parsing mechanism.

We'll start with the easy ones that take no operands, then work our way
up to operators with one and ultimately two arguments. In other words,
we will write the three procedures \\{do\_nullary}, \\{do\_unary}, and \\{do%
\_binary}
that are invoked periodically by the expression scanners.

\fi

\M751. First let's make sure that all of the primitive operators are in the
hash table. Although \\{scan\_primary} and its relatives made use of the
\\{cmd} code for these operators, the \\{do} routines base everything
on the $\mathbin{\&{mod}}$ code. For example, \\{do\_binary} doesn't care
whether the
operation it performs is a \\{primary\_binary} or \\{secondary\_binary}, etc.

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"jobname"},\39\\{nullary},\39\\{job\_name\_op})$;\6
$\\{primitive}(\.{"readstring"},\39\\{nullary},\39\\{read\_string\_op})$;\6
$\\{primitive}(\.{"pencircle"},\39\\{nullary},\39\\{pen\_circle})$;\6
$\\{primitive}(\.{"normaldeviate"},\39\\{nullary},\39\\{normal\_deviate})$;\6
$\\{primitive}(\.{"odd"},\39\\{unary},\39\\{odd\_op})$;\6
$\\{primitive}(\.{"unknown"},\39\\{unary},\39\\{unknown})$;\6
$\\{primitive}(\.{"not"},\39\\{unary},\39\\{not\_op})$;\6
$\\{primitive}(\.{"decimal"},\39\\{unary},\39\\{decimal})$;\6
$\\{primitive}(\.{"reverse"},\39\\{unary},\39\\{reverse})$;\6
$\\{primitive}(\.{"makepen"},\39\\{unary},\39\\{make\_pen\_op})$;\6
$\\{primitive}(\.{"oct"},\39\\{unary},\39\\{oct\_op})$;\6
$\\{primitive}(\.{"hex"},\39\\{unary},\39\\{hex\_op})$;\6
$\\{primitive}(\.{"ord"},\39\\{unary},\39\\{ord\_op})$;\6
$\\{primitive}(\.{"char"},\39\\{unary},\39\\{char\_op})$;\6
$\\{primitive}(\.{"length"},\39\\{unary},\39\\{length\_op})$;\6
$\\{primitive}(\.{"xpart"},\39\\{unary},\39\\{x\_part})$;\6
$\\{primitive}(\.{"ypart"},\39\\{unary},\39\\{y\_part})$;\6
$\\{primitive}(\.{"xxpart"},\39\\{unary},\39\\{xx\_part})$;\6
$\\{primitive}(\.{"xypart"},\39\\{unary},\39\\{xy\_part})$;\6
$\\{primitive}(\.{"yxpart"},\39\\{unary},\39\\{yx\_part})$;\6
$\\{primitive}(\.{"yypart"},\39\\{unary},\39\\{yy\_part})$;\6
$\\{primitive}(\.{"sqrt"},\39\\{unary},\39\\{sqrt\_op})$;\6
$\\{primitive}(\.{"mexp"},\39\\{unary},\39\\{m\_exp\_op})$;\6
$\\{primitive}(\.{"mlog"},\39\\{unary},\39\\{m\_log\_op})$;\6
$\\{primitive}(\.{"sind"},\39\\{unary},\39\\{sin\_d\_op})$;\6
$\\{primitive}(\.{"cosd"},\39\\{unary},\39\\{cos\_d\_op})$;\6
$\\{primitive}(\.{"arctand"},\39\\{unary},\39\\{arctan\_d\_op})$;\6
$\\{primitive}(\.{"trunc"},\39\\{unary},\39\\{trunc\_op})$;\6
$\\{primitive}(\.{"uniformdeviate"},\39\\{unary},\39\\{uniform\_deviate})$;\6
$\\{primitive}(\.{"+"},\39\\{plus\_or\_minus},\39\\{plus})$;\6
$\\{primitive}(\.{"-"},\39\\{plus\_or\_minus},\39\\{minus})$;\6
$\\{primitive}(\.{"*"},\39\\{secondary\_binary},\39\\{times})$;\6
$\\{primitive}(\.{"/"},\39\\{secondary\_binary},\39\\{over})$;\6
$\\{primitive}(\.{"++"},\39\\{tertiary\_binary},\39\\{pythag})$;\6
$\\{primitive}(\.{"and"},\39\\{and\_command},\39\\{and\_op})$;\6
$\\{primitive}(\.{"or"},\39\\{tertiary\_binary},\39\\{or\_op})$;\6
$\\{primitive}(\.{"<"},\39\\{expression\_binary},\39\\{less\_than})$;\6
$\\{primitive}(\.{"<="},\39\\{expression\_binary},\39\\{less\_or\_equal})$;\6
$\\{primitive}(\.{">"},\39\\{expression\_binary},\39\\{greater\_than})$;\6
$\\{primitive}(\.{">="},\39\\{expression\_binary},\39\\{greater\_or\_equal})$;\6
$\\{primitive}(\.{"="},\39\\{equals},\39\\{equal\_to})$;\6
$\\{primitive}(\.{"<>"},\39\\{expression\_binary},\39\\{unequal\_to})$;\6
$\\{primitive}(\.{"substring"},\39\\{primary\_binary},\39\\{substring\_of})$;\6
$\\{primitive}(\.{"subpath"},\39\\{primary\_binary},\39\\{subpath\_of})$;\6
$\\{primitive}(\.{"cull"},\39\\{primary\_binary},\39\\{cull\_of})$;\6
$\\{primitive}(\.{"directiontime"},\39\\{primary\_binary},\39\\{direction\_time%
\_of})$;\6
$\\{primitive}(\.{"point"},\39\\{primary\_binary},\39\\{point\_of})$;\6
$\\{primitive}(\.{"direction"},\39\\{primary\_binary},\39\\{direction\_of})$;\6
$\\{primitive}(\.{"precontrol"},\39\\{primary\_binary},\39\\{precontrol\_of})$;%
\6
$\\{primitive}(\.{"postcontrol"},\39\\{primary\_binary},\39\\{postcontrol%
\_of})$;\6
$\\{primitive}(\.{"penoffset"},\39\\{primary\_binary},\39\\{penoffset\_of})$;\6
$\\{primitive}(\.{"\&"},\39\\{ampersand},\39\\{concatenate})$;\6
$\\{primitive}(\.{"union"},\39\\{tertiary\_binary},\39\\{union})$;\6
$\\{primitive}(\.{"rotated"},\39\\{secondary\_binary},\39\\{rotated\_by})$;\6
$\\{primitive}(\.{"slanted"},\39\\{secondary\_binary},\39\\{slanted\_by})$;\6
$\\{primitive}(\.{"scaled"},\39\\{secondary\_binary},\39\\{scaled\_by})$;\6
$\\{primitive}(\.{"shifted"},\39\\{secondary\_binary},\39\\{shifted\_by})$;\6
$\\{primitive}(\.{"transformed"},\39\\{secondary\_binary},\39\\{transformed%
\_by})$;\6
$\\{primitive}(\.{"xmult"},\39\\{secondary\_binary},\39\\{x\_mult})$;\6
$\\{primitive}(\.{"ymult"},\39\\{secondary\_binary},\39\\{y\_mult})$;\6
$\\{primitive}(\.{"zmult"},\39\\{secondary\_binary},\39\\{z\_mult})$;\6
$\\{primitive}(\.{"intersect"},\39\\{tertiary\_binary},\39\\{intersect})$;\par
\fi

\M752. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4$\\{nullary},\39\\{unary},\39\\{primary\_binary},\39\\{secondary\_binary},\39%
\\{tertiary\_binary},\39\\{expression\_binary},\39\\{plus\_or\_minus},\39%
\\{ampersand},\39\\{equals},\39\\{and\_command}$: \37$\\{print\_op}(\mathbin{%
\&{mod}})$;\par
\fi

\M753. OK, let's look at the simplest \\{do} procedure first.

\Y\P\4\&{procedure}\1\  \37$\\{do\_nullary}(\|c:\\{quarterword})$;\2\6
\&{begin} \37\\{check\_arith};\6
\&{if} $\\{internal}[\\{tracing\_commands}]>0$ \1\&{then}\5
$\\{show\_cmd\_mod}(\\{nullary},\39\|c)$;\2\6
\&{case} $\|c$ \1\&{of}\6
\4\\{normal\_deviate}: \37\&{begin} \37$\\{cur\_type}\K\\{known}$;\5
$\\{cur\_exp}\K\\{norm\_rand}$;\6
\&{end};\6
\4\&{othercases} \37\&{begin} \37$\\{print\_err}(\.{"Not\ yet\ implemented:\
"})$;\5
$\\{print\_op}(\|c)$;\5
$\\{help2}(\.{"Please\ bear\ with\ the\ author\ until\ he\ has\ time\ to\
finish."})$\6
$(\.{"Meanwhile\ the\ value\ 0\ is\ being\ returned."})$;\5
$\\{cur\_type}\K\\{known}$;\5
$\\{cur\_exp}\K0$;\5
\\{error};\6
\&{end}\C{later I'll put $\\{confusion}(\.{"nullary"})$ here}\2\6
\&{endcases};\6
\\{check\_arith};\6
\&{end};\par
\fi

\M754. Things get a bit more interesting when there's an operand. The
operand to \\{do\_unary} appears in \\{cur\_type} and \\{cur\_exp}.

\Y\P\X755:Declare unary action procedures\X\6
\4\&{procedure}\1\  \37$\\{do\_unary}(\|c:\\{quarterword})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37\\{check\_arith};\6
\&{if} $\\{internal}[\\{tracing\_commands}]>0$ \1\&{then}\5
\X756:Trace the current unary operation\X;\2\6
\&{case} $\|c$ \1\&{of}\6
\4\\{plus}: \37\&{if} $\\{cur\_type}<\\{pair\_type}$ \1\&{then}\5
$\\{bad\_unary}(\\{plus})$;\2\6
\4\\{minus}: \37\X757:Negate the current expression\X;\6
\hbox{\4}\X759:Additional cases of unary operators\X\6
\4\&{othercases} \37\&{begin} \37$\\{exp\_err}(\.{"Not\ yet\ implemented:\
"})$;\5
$\\{print\_op}(\|c)$;\5
$\\{help2}(\.{"Please\ bear\ with\ the\ author\ until\ he\ has\ time\ to\
finish."})$\6
$(\.{"Meanwhile\ the\ argument\ (shown\ above)\ is\ being\ returned."})$;\5
\\{error};\6
\&{end}\C{later I'll put $\\{confusion}(\.{"unary"})$ here}\2\6
\&{endcases};\6
\\{check\_arith};\6
\&{end};\par
\fi

\M755. \P$\X755:Declare unary action procedures\X\S$\6
\4\&{procedure}\1\  \37$\\{bad\_unary}(\|c:\\{quarterword})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{a pair node}\2\6
\&{begin} \37$\\{exp\_err}(\.{"Not\ implemented:\ "})$;\5
$\\{print\_op}(\|c)$;\5
$\\{print\_char}(\.{"("})$;\6
\&{if} $\\{cur\_type}<\\{dependent}$ \1\&{then}\6
\&{if} $\\{cur\_type}\I\\{pair\_type}$ \1\&{then}\5
$\\{print\_type}(\\{cur\_type})$\6
\4\&{else} \&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\6
\&{if} $(\\{type}(\\{x\_part\_loc}(\|p))\I\\{known})\V(\\{type}(\\{y\_part%
\_loc}(\|p))\I\\{known})$ \1\&{then}\5
$\\{print}(\.{"unknown\ pair"})$\6
\4\&{else} $\\{print}(\.{"pair"})$;\2\6
\&{end}\2\6
\4\&{else} $\\{print}(\.{"unknown\ numeric"})$;\2\6
$\\{print\_char}(\.{")"})$;\5
$\\{help3}(\.{"This\ operation\ isn\'t\ in\ my\ repertoire,\ because\ the\
argument"})$\6
$(\.{"has\ the\ wrong\ type.\ Continue,\ and\ I\'ll\ simply\ return\ the"})$\6
$(\.{"argument\ (shown\ above)\ as\ the\ result\ of\ the\ operation."})$;\5
\\{error};\6
\&{end};\par
\A section~758.
\U section~754.\fi

\M756. \P$\X756:Trace the current unary operation\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\{"})$;\5
$\\{print\_op}(\|c)$;\5
$\\{print\_char}(\.{"("})$;\6
$\\{print\_exp}(\\{null},\39\\{false})$;\C{show the operand, but not verbosely}%
\6
$\\{print\_char}(\.{")"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~754.\fi

\M757. \P$\X757:Negate the current expression\X\S$\6
\&{case} $\\{cur\_type}$ \1\&{of}\6
\4\\{pair\_type}: \37\&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\6
\&{if} $\\{type}(\\{x\_part\_loc}(\|p))=\\{known}$ \1\&{then}\5
$\\{negate}(\\{value}(\\{x\_part\_loc}(\|p)))$\6
\4\&{else} $\\{negate\_dep\_list}(\\{dep\_list}(\\{x\_part\_loc}(\|p)))$;\2\6
\&{if} $\\{type}(\\{y\_part\_loc}(\|p))=\\{known}$ \1\&{then}\5
$\\{negate}(\\{value}(\\{y\_part\_loc}(\|p)))$\6
\4\&{else} $\\{negate\_dep\_list}(\\{dep\_list}(\\{y\_part\_loc}(\|p)))$;\2\6
\&{end};\6
\4$\\{dependent},\39\\{proto\_dependent}$: \37$\\{negate\_dep\_list}(\\{cur%
\_exp})$;\6
\4\\{known}: \37$\\{negate}(\\{cur\_exp})$;\6
\4\&{othercases} \37$\\{bad\_unary}(\\{minus})$\2\6
\&{endcases}\par
\U section~754.\fi

\M758. \P$\X755:Declare unary action procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{negate\_dep\_list}(\|p:\\{pointer})$;\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\~ \1\&{loop}\ \&{begin} \37$\\{negate}(\\{value}(\|p))$;\6
\&{if} $\\{info}(\|p)=\\{null}$ \1\&{then}\5
\&{return};\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M759. \P$\X759:Additional cases of unary operators\X\S$\6
\4$\\{sqrt\_op},\39\\{m\_exp\_op},\39\\{m\_log\_op},\39\\{sin\_d\_op},\39\\{cos%
\_d\_op},\39\\{trunc\_op},\39\\{uniform\_deviate}$: \37\&{if} $\\{cur\_type}\I%
\\{known}$ \1\&{then}\5
$\\{bad\_unary}(\|c)$\6
\4\&{else} \&{case} $\|c$ \1\&{of}\6
\4\\{sqrt\_op}: \37$\\{cur\_exp}\K\\{square\_rt}(\\{cur\_exp})$;\6
\4\\{m\_exp\_op}: \37$\\{cur\_exp}\K\\{m\_exp}(\\{cur\_exp})$;\6
\4\\{m\_log\_op}: \37$\\{cur\_exp}\K\\{m\_log}(\\{cur\_exp})$;\6
\4$\\{sin\_d\_op},\39\\{cos\_d\_op}$: \37\&{begin} \37\&{if} $\\{abs}(\\{cur%
\_exp})\G\\{fraction\_half}$ \1\&{then}\5
$\\{cur\_exp}\K\\{cur\_exp}\mathbin{\&{mod}}23592960$;\C{that's $360\ast%
\\{unity}$}\2\6
$\\{n\_sin\_cos}(\\{cur\_exp}\ast16)$;\6
\&{if} $\|c=\\{sin\_d\_op}$ \1\&{then}\5
$\\{cur\_exp}\K(\\{n\_sin}+\O{4000})\mathbin{\&{div}}\O{10000}$\6
\4\&{else} $\\{cur\_exp}\K(\\{n\_cos}+\O{4000})\mathbin{\&{div}}\O{10000}$;\2\6
\&{end};\6
\4\\{trunc\_op}: \37$\\{cur\_exp}\K\\{trunc\_scaled}(\\{cur\_exp})$;\6
\4\\{uniform\_deviate}: \37$\\{cur\_exp}\K\\{unif\_rand}(\\{cur\_exp})$;\2\6
\&{end};\C{there are no other cases}\2\par
\A section~760.
\U section~754.\fi

\M760. \P$\X759:Additional cases of unary operators\X\mathrel{+}\S$\6
\4\\{arctan\_d\_op}: \37\&{if} $\\{cur\_type}\I\\{pair}$ \1\&{then}\5
$\\{bad\_unary}(\\{arctan\_d\_op})$\6
\4\&{else} \&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\6
\&{if} $(\\{type}(\\{x\_part\_loc}(\|p))\I\\{known})\V(\\{type}(\\{y\_part%
\_loc}(\|p))\I\\{known})$ \1\&{then}\5
$\\{bad\_unary}(\\{arctan\_d\_op})$\6
\4\&{else} $\\{flush\_cur\_exp}(\\{n\_atan}(\\{value}(\\{x\_part\_loc}(\|p)),%
\39\\{value}(\\{y\_part\_loc}(\|p)))\mathbin{\&{div}}16)$;\2\6
\&{end};\2\par
\fi

\M761. Finally, we have the operations that combine a capsule~\|p
with the current expression.

\Y\P\X762:Declare binary action procedures\X\6
\4\&{procedure}\1\  \37$\\{do\_binary}(\|p:\\{pointer};\,\35\|c:%
\\{quarterword})$;\6
\4\&{var} \37$\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list manipulation}\2\6
\&{begin} \37\\{check\_arith};\6
\&{if} $\\{internal}[\\{tracing\_commands}]>0$ \1\&{then}\5
\X763:Trace the current binary operation\X;\2\6
\&{case} $\|c$ \1\&{of}\6
\4$\\{plus},\39\\{minus}$: \37\X764:Add or subtract the current expression from
\|p\X;\6
\hbox{\4}\X772:Additional cases of binary operators\X\6
\4\&{othercases} \37\&{begin} \37$\\{disp\_err}(\|p,\39\\{true})$;\5
$\\{exp\_err}(\.{"Not\ yet\ implemented:\ "})$;\5
$\\{print\_op}(\|c)$;\5
$\\{help2}(\.{"Please\ bear\ with\ the\ author\ until\ he\ has\ time\ to\
finish."})$\6
$(\.{"Meanwhile\ the\ second\ argument\ (above)\ is\ being\ returned."})$;\5
\\{error};\6
\&{end}\C{later I'll put $\\{confusion}(\.{"binary"})$ here}\2\6
\&{endcases};\6
$\\{recycle\_value}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{value\_node\_size})$;\C{\&{return} to avoid this}\6
\4\\{exit}: \37\\{check\_arith};\6
\&{end};\par
\fi

\M762. \P$\X762:Declare binary action procedures\X\S$\6
\4\&{procedure}\1\  \37$\\{bad\_binary}(\|p:\\{pointer};\,\35\|c:%
\\{quarterword})$;\2\6
\&{begin} \37\\{disp\_err};\5
$\\{exp\_err}(\.{"Not\ implemented:\ ("})$;\6
\&{if} $\\{type}(\|p)<\\{dependent}$ \1\&{then}\5
$\\{print\_type}(\\{type}(\|p))$\6
\4\&{else} $\\{print}(\.{"unknown\ numeric"})$;\2\6
$\\{print\_char}(\.{")"})$;\5
$\\{print\_op}(\|c)$;\5
$\\{print\_char}(\.{"("})$;\6
\&{if} $\\{cur\_type}<\\{dependent}$ \1\&{then}\5
$\\{print\_type}(\\{cur\_type})$\6
\4\&{else} $\\{print}(\.{"unknown\ numeric"})$;\2\6
$\\{print\_char}(\.{")"})$;\5
$\\{help3}(\.{"I\'m\ afraid\ I\ don\'t\ know\ how\ to\ apply\ that\ operation\
to\ that"})$\6
$(\.{"combination\ of\ types.\ Continue,\ and\ I\'ll\ simply\ return\ the"})$\6
$(\.{"second\ argument\ (see\ above)\ as\ the\ result\ of\ the\ operation."})$;%
\5
\\{error};\6
\&{end};\par
\A sections~765, 773, and~776.
\U section~761.\fi

\M763. \P$\X763:Trace the current binary operation\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\{("})$;\5
$\\{print\_exp}(\|p,\39\\{false})$;\C{show the operand, but not verbosely}\6
$\\{print\_char}(\.{")"})$;\5
$\\{print\_op}(\|c)$;\5
$\\{print\_char}(\.{"("})$;\6
$\\{print\_exp}(\\{null},\39\\{false})$;\5
$\\{print\_char}(\.{")"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~761.\fi

\M764. \P$\X764:Add or subtract the current expression from \|p\X\S$\6
\&{if} $(\\{cur\_type}<\\{pair\_type})\V(\\{type}(\|p)<\\{pair\_type})$ \1%
\&{then}\5
$\\{bad\_binary}(\|p,\39\|c)$\6
\4\&{else} \&{if} $\\{cur\_type}=\\{pair\_type}$ \1\&{then}\6
\&{if} $\\{type}(\|p)\I\\{pair\_type}$ \1\&{then}\5
$\\{bad\_binary}(\|p,\39\|c)$\6
\4\&{else} \&{begin} \37$\|q\K\\{value}(\|p)$;\5
$\|r\K\\{value}(\\{cur\_exp})$;\5
$\\{add\_or\_subtract}(\\{x\_part\_loc}(\|q),\39\\{x\_part\_loc}(\|r),\39\|c)$;%
\5
$\\{add\_or\_subtract}(\\{y\_part\_loc}(\|q),\39\\{y\_part\_loc}(\|r),\39\|c)$;%
\6
\&{end}\2\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{pair\_type}$ \1\&{then}\5
$\\{bad\_binary}(\|p,\39\|c)$\6
\4\&{else} $\\{add\_or\_subtract}(\|p,\39\\{null})$\2\2\2\par
\U section~761.\fi

\M765. The first argument to \\{add\_or\_subtract} is the location of a value
node in a capsule that will soon be recycled. The second argument
is either a location within a pair node of \\{cur\_exp}, or it is null
(which means that \\{cur\_exp} itself should be the second argument).
The third argument is either \\{plus} or \\{minus}.

Arithmetic overflow may go undetected; users aren't supposed to be
monkeying around with really big values.

\Y\P$\4\X762:Declare binary action procedures\X\mathrel{+}\S$\6
\X771:Declare the procedure called \\{dep\_finish}\X\6
\4\&{procedure}\1\  \37$\\{add\_or\_subtract}(\|p,\39\|q:\\{pointer};\,\35\|c:%
\\{quarterword})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|t: \37\\{small\_number};\C{second operand type}\6
\|v: \37\\{integer};\C{second operand value}\6
\&{begin} \37\&{if} $\|q=\\{null}$ \1\&{then}\6
\&{begin} \37$\|t\K\\{cur\_type}$;\5
$\|v\K\\{cur\_exp}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|t\K\\{type}(\|q)$;\6
\&{if} $\|t<\\{dependent}$ \1\&{then}\5
$\|v\K\\{value}(\|q)$\ \&{else} $\|v\K\\{dep\_list}(\|q)$;\2\6
\&{end};\2\6
\&{if} $\|t=\\{known}$ \1\&{then}\6
\&{begin} \37\&{if} $\|c=\\{minus}$ \1\&{then}\5
$\\{negate}(\|v)$;\2\6
\&{if} $\\{type}(\|p)=\\{known}$ \1\&{then}\6
\&{begin} \37$\|v\K\\{value}(\|p)+\|v$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{cur\_exp}\K\|v$\ \&{else} $\\{value}(\|q)\K\|v$;\2\6
\&{return};\5
\X766:Add a known value to the constant term of $\\{dep\_list}(\|p)$\X;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\|c=\\{minus}$ \1\&{then}\5
$\\{negate\_dep\_list}(\|v)$;\2\6
\X767:Add operand \|p to the dependency list \|v\X;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\2\par
\fi

\M766. It's necessary to remember that operand \|p is one of the
dependencies reachable from \\{dep\_head}, but the result after addition
should be such a dependency if and only if $\|q\I\\{null}$. This complication
has arisen because of the author's (possibly misguided) attempts
at efficiency; the alternative of putting \\{cur\_exp} in and out of the
\\{dep\_head} list seems wasteful, even though such operations probably
wouldn't slow things down substantially.

\Y\P$\4\X766:Add a known value to the constant term of $\\{dep\_list}(\|p)$\X%
\S$\6
$\|r\K\\{dep\_list}(\|p)$;\6
\&{while} $\\{info}(\|r)\I\\{null}$ \1\&{do}\5
$\|r\K\\{link}(\|r)$;\2\6
$\\{value}(\|r)\K\\{value}(\|r)+\|v$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{cur\_exp}\K\\{dep\_list}(\|p)$;\5
$\\{cur\_type}\K\\{type}(\|p)$;\5
$\\{prev\_dep}(\\{link}(\|r))\K\\{prev\_dep}(\|p)$;\5
$\\{link}(\\{prev\_dep}(\|p))\K\\{link}(\|r)$;\5
$\\{link}(\|r)\K\\{null}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{dep\_list}(\|q)\K\\{dep\_list}(\|p)$;\5
$\\{type}(\|q)\K\\{type}(\|p)$;\5
$\\{prev\_dep}(\|q)\K\\{prev\_dep}(\|p)$;\5
$\\{link}(\\{prev\_dep}(\|p))\K\|q$;\6
\&{end};\2\6
$\\{type}(\|p)\K\\{known}$;\C{this will keep the recycler from collecting
non-garbage}\par
\U section~765.\fi

\M767. We prefer \\{dependent} lists to \\{proto\_dependent} ones, because it
is
nice to retain the extra accuracy of \\{fraction} coefficients.

\Y\P$\4\X767:Add operand \|p to the dependency list \|v\X\S$\6
\&{if} $\\{type}(\|p)=\\{known}$ \1\&{then}\5
\X769:Add the known $\\{value}(\|p)$ to the constant term of \|v\X\6
\4\&{else} \&{begin} \37$\|s\K\\{type}(\|p)$;\5
$\|r\K\\{dep\_list}(\|p)$;\6
\&{if} $\|t=\\{dependent}$ \1\&{then}\6
\&{begin} \37\&{if} $\|s=\\{dependent}$ \1\&{then}\6
\&{if} $\\{max\_coef}(\|r)+\\{max\_coef}(\|v)<\\{coef\_bound}$ \1\&{then}\6
\&{begin} \37$\|v\K\\{p\_plus\_fq}(\|v,\39\\{fraction\_one},\39\|r,\39%
\\{dependent})$;\5
\&{goto} \37\\{done};\6
\&{end};\C{\\{fix\_needed} will necessarily be false}\2\2\6
\X768:Change list $(\|t,\|v)$ to \\{proto\_dependent}\X;\6
\&{end};\2\6
\&{if} $\|s=\\{proto\_dependent}$ \1\&{then}\5
$\|v\K\\{p\_plus\_fq}(\|v,\39\\{fraction\_one},\39\|r,\39\\{dependent})$\C{yes,
this works, because \|v and \|r are the same type}\6
\4\&{else} $\|v\K\\{p\_plus\_fq}(\|v,\39\\{unity},\39\|r,\39\\{proto%
\_dependent})$;\2\6
\&{if} $\\{fix\_needed}$ \1\&{then}\5
\\{fix\_dependencies};\2\6
\4\\{done}: \37\X770:Output the answer, \|v (which might have become \\{known})%
\X;\6
\&{end}\2\par
\U section~765.\fi

\M768. \P$\X768:Change list $(\|t,\|v)$ to \\{proto\_dependent}\X\S$\6
$\|t\K\\{proto\_dependent}$;\5
$\|u\K\|v$;\6
\&{while} $\\{info}(\|u)\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{value}(\|u)\K(\\{value}(\|u)+\O{4000})\mathbin{\&{div}}%
\O{10000}$;\5
$\|u\K\\{link}(\|u)$;\6
\&{end}\2\par
\U section~767.\fi

\M769. \P$\X769:Add the known $\\{value}(\|p)$ to the constant term of \|v\X\S$%
\6
\&{begin} \37\&{while} $\\{info}(\|v)\I\\{null}$ \1\&{do}\5
$\|v\K\\{link}(\|v)$;\2\6
$\\{value}(\|v)\K\\{value}(\|p)+\\{value}(\|v)$;\6
\&{end}\par
\U section~767.\fi

\M770. \P$\X770:Output the answer, \|v (which might have become \\{known})\X\S$%
\6
$\\{dep\_finish}(\|v,\39\|q,\39\|t)$\par
\U section~767.\fi

\M771. Here's the current situation: The dependency list \|v of type \|t
should either be put into the current expression (if $\|q=\\{null}$) or
into location \|q within a pair node (otherwise). In the latter case,
location \|q formerly held a dependency list with the same
final pointer as the list \|v.

\Y\P$\4\X771:Declare the procedure called \\{dep\_finish}\X\S$\6
\4\&{procedure}\1\  \37$\\{dep\_finish}(\|v,\39\|q:\\{pointer};\,\35\|t:%
\\{small\_number})$;\2\6
\&{begin} \37\&{if} $\\{info}(\|v)=\\{null}$ \1\&{then}\6
\&{if} $\|q=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{cur\_exp}\K\\{value}(\|v)$;\5
$\\{cur\_type}\K\\{known}$;\5
$\\{free\_node}(\|v,\39\\{value\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|v\K\\{value}(\|v)$;\5
$\\{recycle\_value}(\|q)$;\5
$\\{value}(\|q)\K\|v$;\5
$\\{type}(\|q)\K\\{known}$;\6
\&{end}\2\6
\4\&{else} \&{if} $\|q=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{cur\_exp}\K\|v$;\5
$\\{cur\_type}\K\|t$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{dep\_list}(\|q)\K\|v$;\5
$\\{type}(\|q)\K\|t$;\6
\&{end};\2\2\6
\&{end};\par
\U section~765.\fi

\M772. \P$\X772:Additional cases of binary operators\X\S$\6
\4\\{times}: \37\&{if} $(\\{cur\_type}<\\{pair\_type})\V(\\{type}(\|p)<\\{pair%
\_type})\V\30((\\{cur\_type}\I\\{known})\W(\\{type}(\|p)\I\\{known}))$ \1%
\&{then}\5
$\\{bad\_binary}(\|p,\39\\{times})$\6
\4\&{else} \&{begin} \37\&{if} $\\{type}(\|p)=\\{known}$ \1\&{then}\6
\&{begin} \37$\|v\K\\{value}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{value\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|v\K\\{cur\_exp}$;\5
$\\{unstash\_cur\_exp}(\|p)$;\6
\&{end};\2\6
\&{if} $\\{cur\_type}=\\{known}$ \1\&{then}\5
$\\{take\_scaled}(\\{cur\_exp},\39\|v)$\6
\4\&{else} \&{if} $\\{cur\_type}=\\{pair\_type}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\5
$\\{dep\_mult}(\\{x\_part\_loc}(\|p),\39\|v,\39\\{true})$;\5
$\\{dep\_mult}(\\{y\_part\_loc}(\|p),\39\|v,\39\\{true})$;\6
\&{end}\6
\4\&{else} $\\{dep\_mult}(\\{null},\39\|v,\39\\{true})$;\2\2\6
\&{return};\6
\&{end};\2\par
\A section~775.
\U section~761.\fi

\M773. \P$\X762:Declare binary action procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{dep\_mult}(\|p:\\{pointer};\,\35\|v:\\{integer};\,%
\35\\{v\_is\_scaled}:\\{boolean})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the dependency list being multiplied by %
\|v}\6
$\|s,\39\|t$: \37\\{small\_number};\C{its type, before and after}\6
\|w: \37\\{fraction};\C{maximum coefficient}\2\6
\&{begin} \37\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\|t\K\\{cur\_type}$;\5
$\|q\K\\{cur\_exp}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|t\K\\{type}(\|p)$;\5
$\|q\K\\{dep\_list}(\|p)$;\6
\&{end};\2\6
$\|s\K\|t$;\6
\&{if} $\|t=\\{dependent}$ \1\&{then}\6
\&{if} $\\{v\_is\_scaled}$ \1\&{then}\6
\&{begin} \37$\|w\K\\{max\_coef}(\|q)$;\6
\&{if} $\\{ab\_geq\_cd}(\|w,\39\\{abs}(\|v),\39\\{coef\_threshold}-1,\39\|u)$ %
\1\&{then}\5
$\|t\K\\{proto\_dependent}$;\2\6
\&{end};\2\2\6
$\|q\K\\{p\_times\_v}(\|q,\39\|v,\39\|s,\39\|t,\39\\{v\_is\_scaled})$;\5
$\\{dep\_finish}(\|q,\39\|p,\39\|t)$;\6
\&{end};\par
\fi

\M774. Here is a routine that is similar to \\{times}; but it is invoked only
internally, when \|v is a \\{fraction} whose magnitude is at most~1,
and when $\\{cur\_type}\G\\{pair\_type}$.

\Y\P$\4\X684:Declare subroutines needed for expression parsing\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{frac\_mult}(\|v:\\{fraction})$;\C{multiplies \\{cur%
\_exp} by \|v}\6
\4\&{var} \37\|p: \37\\{pointer};\C{a pair node}\2\6
\&{begin} \37\&{if} $\\{cur\_type}=\\{known}$ \1\&{then}\5
$\\{take\_fraction}(\\{cur\_exp},\39\|v)$\6
\4\&{else} \&{if} $\\{cur\_type}=\\{pair\_type}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\5
$\\{dep\_mult}(\\{x\_part\_loc}(\|p),\39\|v,\39\\{false})$;\5
$\\{dep\_mult}(\\{y\_part\_loc}(\|p),\39\|v,\39\\{false})$;\6
\&{end}\6
\4\&{else} $\\{dep\_mult}(\\{null},\39\|v,\39\\{false})$;\2\2\6
\&{end};\par
\fi

\M775. \P$\X772:Additional cases of binary operators\X\mathrel{+}\S$\6
\4\\{over}: \37\&{if} $(\\{cur\_type}\I\\{known})\V(\\{type}(\|p)<\\{pair%
\_type})$ \1\&{then}\5
$\\{bad\_binary}(\|p,\39\\{over})$\6
\4\&{else} \&{begin} \37$\|v\K\\{cur\_exp}$;\5
$\\{unstash\_cur\_exp}(\|p)$;\6
\&{if} $\|v=0$ \1\&{then}\5
\X777:Report division by zero error\X\6
\4\&{else} \&{begin} \37\&{if} $\\{cur\_type}=\\{known}$ \1\&{then}\5
$\\{make\_scaled}(\\{cur\_exp},\39\|v)$\6
\4\&{else} \&{if} $\\{cur\_type}=\\{pair\_type}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{value}(\\{cur\_exp})$;\5
$\\{dep\_div}(\\{x\_part\_loc}(\|p),\39\|v)$;\5
$\\{dep\_div}(\\{y\_part\_loc}(\|p),\39\|v)$;\6
\&{end}\6
\4\&{else} $\\{dep\_div}(\\{null},\39\|v)$;\2\2\6
\&{end};\2\6
\&{return};\6
\&{end};\2\par
\fi

\M776. \P$\X762:Declare binary action procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{dep\_div}(\|p:\\{pointer};\,\35\|v:\\{scaled})$;\6
\4\&{var} \37\|q: \37\\{pointer};\C{the dependency list being divided by \|v}\6
$\|s,\39\|t$: \37\\{small\_number};\C{its type, before and after}\6
\|w: \37\\{fraction};\C{maximum coefficient}\2\6
\&{begin} \37\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\|t\K\\{cur\_type}$;\5
$\|q\K\\{cur\_exp}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|t\K\\{type}(\|p)$;\5
$\|q\K\\{dep\_list}(\|p)$;\6
\&{end};\2\6
$\|s\K\|t$;\6
\&{if} $\|t=\\{dependent}$ \1\&{then}\6
\&{begin} \37$\|w\K\\{max\_coef}(\|q)$;\6
\&{if} $\\{ab\_geq\_cd}(\|w,\39\\{unity},\39\\{coef\_threshold}-1,\39\\{abs}(%
\|v))$ \1\&{then}\5
$\|t\K\\{proto\_dependent}$;\2\6
\&{end};\2\6
$\|q\K\\{p\_over\_v}(\|q,\39\|v,\39\|s,\39\|t)$;\5
$\\{dep\_finish}(\|q,\39\|p,\39\|t)$;\6
\&{end};\par
\fi

\M777. \P$\X777:Report division by zero error\X\S$\6
\&{begin} \37$\\{exp\_err}(\.{"Division\ by\ zero"})$;\5
$\\{help2}(\.{"You\'re\ trying\ to\ divide\ the\ quantity\ shown\ above\ the\
error"})$\6
$(\.{"message\ by\ zero.\ I\'m\ using\ that\ quantity\ as\ my\ answer."})$;\5
\\{error};\6
\&{end}\par
\U section~775.\fi

\N778.  \[xx] Statements and commands.
The chief execture of \MF\ is the \\{do\_statement} routine, which
contains the master switch that causes all the various pieces of \MF\
to do their things, in the right order.

In a sense, this is the grand climax of the program: It applies all of the
tools that we have worked so hard to construct. In another sense, this is
the messiest part of the program: It necessarily refers to other pieces
of code all over the place, so that a person can't fully understand what is
going on without paging back and forth to be reminded of conventions that
are defined elsewhere. We are now at the hub of the web.

The structure of \\{do\_statement} itself is quite simple.
There's a label called \\{big\_switch}, at which point the next
token of input is fetched using \\{get\_x\_next}. If the next token
can be the first token of an expression, we look for an equation,
an assignment, or a title. Otherwise the program uses a \&{case}
construction to branch at high speed between the various and
other sundry types of commands, each of which has an ``action procedure''
that does the necessary work.

\Y\P\D \37$\\{big\_switch}=60$\C{o here to branch on the next token of input}%
\par
\Y\P\X790:Declare action procedures for use by \\{do\_statement}\X\6
\4\&{procedure}\1\  \37\\{do\_statement};\C{governs \MF's activities}\6
\4\&{label} \37\\{big\_switch};\2\6
\&{begin} \37$\\{print\_err}(\.{"Not\ yet\ implemented:\ anything"})$;\5
$\\{error\_count}\K0$;\C{NOTE THAT I PROMISED THIS IN THE ERROR ROUTINE!}\6
\&{end};\par
\fi

\M779. \MF\ never defines the tokens `\.(' and `\.)' to be primitives, but
plain \MF\ begins with the declaration `\&{delimiters} \.{()}'. Such a
declaration assigns the command code \\{left\_delimiter} to `\.{(}' and
\\{right\_delimiter} to `\.{)}'; the \\{equiv} of each delimiter is the
hash address of its mate.

Here is a procedure that is called when \MF\ has reached a point
where some right delimiter is mandatory.

\Y\P$\4\X779:Declare the procedure called \\{check\_delimiter}\X\S$\6
\4\&{procedure}\1\  \37$\\{check\_delimiter}(\\{l\_delim},\39\\{r\_delim}:%
\\{pointer})$;\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\&{if} $\\{cur\_cmd}=\\{right\_delimiter}$ \1\&{then}\6
\&{if} $\\{cur\_mod}=\\{l\_delim}$ \1\&{then}\5
\&{return};\2\2\6
\&{if} $\\{cur\_sym}\I\\{r\_delim}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ "})$;\5
$\\{print}(\\{text}(\\{r\_delim}))$;\5
$\\{print}(\.{"\ has\ been\ inserted"})$;\5
$\\{help2}(\.{"I\ found\ no\ right\ delimiter\ to\ match\ a\ left\ one.\ So\ I%
\'ve"})$\6
$(\.{"put\ one\ in,\ behind\ the\ scenes;\ this\ may\ fix\ the\ problem."})$;\5
\\{back\_error};\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"The\ token\ "})$;\5
$\\{print}(\\{text}(\\{r\_delim}))$;\5
$\\{print}(\.{"\ is\ no\ longer\ a\ right\ delimiter"})$;\5
$\\{help3}(\.{"Strange:\ This\ token\ has\ lost\ its\ former\ meaning!"})$\6
$(\.{"I\'ll\ read\ it\ as\ a\ right\ delimiter\ this\ time;"})$\6
$(\.{"but\ watch\ out,\ I\'ll\ probably\ miss\ it\ later."})$;\5
\\{error};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\U section~563.\fi

\M780. Here is a routine that's used whenever a token will be redefined. If
the user's token is unredefinable, the `\\{frozen\_inaccessible}' token is
substituted; the latter is redefinable but essentially impossible to use,
hence \MF's tables won't get fouled up.

\Y\P\4\&{procedure}\1\  \37\\{get\_symbol};\C{sets \\{cur\_sym} to a safe
symbol}\6
\4\&{label} \37\\{restart};\2\6
\&{begin} \37\\{restart}: \37\\{get\_next};\6
\&{if} $(\\{cur\_sym}=0)\V(\\{cur\_sym}>\\{frozen\_inaccessible})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ symbolic\ token\ inserted"})$;\5
$\\{help3}(\.{"Sorry:\ You\ can\'t\ redefine\ a\ number\ or\ a\ string."})$\6
$(\.{"I\'ve\ inserted\ an\ inaccessible\ symbol\ so\ that\ your"})$\6
$(\.{"definition\ will\ be\ completed\ without\ mixing\ me\ up\ too\
badly."})$;\6
\&{if} $\\{cur\_sym}=0$ \1\&{then}\5
\\{back\_input};\2\6
$\\{cur\_sym}\K\\{frozen\_inaccessible}$;\5
\\{ins\_error};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\par
\fi

\M781. Our next goal is to process type declarations. For this purpose it's
convenient to have a procedure that scans a $\langle\,$declared
variable$,\rangle$ and returns the corresponding token list. After the
following procedure has acted, the token after the declared variable
will have been scanned, so it will appear in \\{cur\_cmd}, \\{cur\_mod},
and~\\{cur\_sym}.

\Y\P\4\&{function}\1\  \37\\{scan\_declared\_variable}: \37\\{pointer};\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|x: \37\\{pointer};\C{hash address of the variable's root}\6
$\|h,\39\|t$: \37\\{pointer};\C{head and tail of the token list to be returned}%
\6
\|l: \37\\{pointer};\C{hash address of left bracket}\2\6
\&{begin} \37\\{get\_symbol};\5
$\|x\K\\{cur\_sym}$;\6
\&{if} $\\{eq\_type}(\|x)\I\\{name}$ \1\&{then}\5
$\\{eq\_type}(\|x)\K\\{name}$;\2\6
\&{if} $\\{equiv}(\|x)=\\{null}$ \1\&{then}\5
$\\{new\_root}(\|x)$;\2\6
$\|h\K\\{get\_avail}$;\5
$\\{info}(\|h)\K\|x$;\5
$\|t\K\|h$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_sym}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{eq\_type}(\\{cur\_sym})\I\\{name}$ \1\&{then}\6
\&{if} $\\{eq\_type}(\\{cur\_sym})=\\{left\_bracket}$ \1\&{then}\5
\X782:Descend past a generic subscript\X\6
\4\&{else} \&{goto} \37\\{done};\2\2\6
$\\{link}(\|t)\K\\{get\_avail}$;\5
$\|t\K\\{link}(\|t)$;\5
$\\{info}(\|t)\K\\{cur\_sym}$;\6
\&{end};\2\6
\4\\{done}: \37$\\{scan\_declared\_variable}\K\|h$;\6
\&{end};\par
\fi

\M782. If the subscript isn't generic, we don't accept it as part of the
declared variable.

\Y\P$\4\X782:Descend past a generic subscript\X\S$\6
\&{begin} \37$\|l\K\\{cur\_sym}$;\5
\\{get\_next};\6
\&{if} $\\{cur\_cmd}\I\\{right\_bracket}$ \1\&{then}\6
\&{begin} \37\\{back\_input};\5
$\\{cur\_sym}\K\|l$;\5
$\\{cur\_cmd}\K\\{left\_bracket}$;\5
\&{goto} \37\\{done};\6
\&{end}\6
\4\&{else} $\\{cur\_sym}\K\\{generic\_subscript}$;\2\6
\&{end}\par
\U section~781.\fi

\M783. Type declarations are introduced by the following primitive operations.

\Y\P$\4\X184:Put each of \MF's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"numeric"},\39\\{type\_name},\39\\{numeric\_type})$;\6
$\\{primitive}(\.{"string"},\39\\{type\_name},\39\\{string\_type})$;\6
$\\{primitive}(\.{"boolean"},\39\\{type\_name},\39\\{boolean\_type})$;\6
$\\{primitive}(\.{"path"},\39\\{type\_name},\39\\{path\_type})$;\6
$\\{primitive}(\.{"pen"},\39\\{type\_name},\39\\{pen\_type})$;\6
$\\{primitive}(\.{"edges"},\39\\{type\_name},\39\\{edges\_type})$;\6
$\\{primitive}(\.{"transform"},\39\\{type\_name},\39\\{transform\_type})$;\6
$\\{primitive}(\.{"pair"},\39\\{type\_name},\39\\{pair\_type})$;\par
\fi

\M784. \P$\X200:Cases of \\{print\_cmd\_mod} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{type\_name}: \37\&{case} $\mathbin{\&{mod}}$ \1\&{of}\6
\4\\{numeric\_type}: \37$\\{print}(\.{"numeric"})$;\6
\4\\{string\_type}: \37$\\{print}(\.{"string"})$;\6
\4\\{boolean\_type}: \37$\\{print}(\.{"boolean"})$;\6
\4\\{path\_type}: \37$\\{print}(\.{"pathc"})$;\6
\4\\{pen\_type}: \37$\\{print}(\.{"pen"})$;\6
\4\\{edges\_type}: \37$\\{print}(\.{"edges"})$;\6
\4\\{transform\_type}: \37$\\{print}(\.{"transform"})$;\6
\4\&{othercases} \37$\\{print}(\.{"pair"})$\2\6
\&{endcases};\par
\fi

\M785. Now we are ready to handle type declarations, assuming that a
\\{type\_name} has just been scanned.

\Y\P\4\&{procedure}\1\  \37\\{do\_type\_declaration};\6
\4\&{var} \37\|t: \37\\{small\_number};\C{the type being declaed}\6
\|p: \37\\{pointer};\C{token list for a declared variable}\2\6
\&{begin} \37$\|t\K\\{cur\_mod}$;\6
\1\&{repeat} \37$\|p\K\\{scan\_declared\_variable}$;\5
$\\{flush\_variable}(\\{equiv}(\\{info}(\|p)),\39\\{link}(\|p),\39\\{false})$;\6
$\|q\K\\{find\_variable}(\|p)$;\5
$\\{type}(\|q)\K\|t$;\5
$\\{value}(\|q)\K\\{null}$;\6
$\\{flush\_list}(\|p)$;\6
\&{if} $\\{cur\_cmd}<\\{comma}$ \1\&{then}\5
\X786:Flush spurious symbols after the declared variable\X;\2\6
\4\&{until}\5
$\\{cur\_cmd}>\\{comma}$;\2\6
\&{end};\par
\fi

\M786. \P$\X786:Flush spurious symbols after the declared variable\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ suffix\ of\ declared\ variable\ will\
be\ flushed"})$;\5
$\\{help5}(\.{"Variables\ in\ declarations\ must\ consist\ entirely\ of"})$\6
$(\.{"names\ and\ generic\ subscripts,\ e.g.,\ \`x[]a\'."})$\6
$(\.{"Are\ you\ trying\ to\ use\ a\ reserved\ word\ in\ a\ variable\ name?"})$\6
$(\.{"I\'m\ going\ to\ discard\ the\ junk\ I\ found\ here,"})$\6
$(\.{"up\ to\ the\ next\ comma\ or\ the\ end\ of\ the\ declaration."})$;\6
\&{if} $\\{cur\_cmd}=\\{numeric\_token}$ \1\&{then}\5
$\\{help\_line}[2]\K\.{"Explicit\ subscripts\ like\ \`x15a\'\ aren\'t\
permitted."}$;\2\6
\\{error};\6
\1\&{repeat} \37\\{get\_next};\6
\4\&{until}\5
$\\{cur\_cmd}\G\\{comma}$;\2\6
\&{end}\par
\U section~785.\fi

\N787.  \[xx] Dumping and undumping the tables.
After \.{INIMF} has seen a collection of macros, it
can write all the necessary information on an auxiliary file so
that production versions of \MF\ are able to initialize their
memory at high speed. The present section of the program takes
care of such output and input. We shall consider simultaneously
the processes of storing and restoring,
so that the inverse relation between them is clear.

The global variable \\{base\_ident} is a string that is printed right
after the \\{banner} line when \MF\ is ready to start. For \.{INIMF} this
string says simply `\.{(INIMF)}'; for other versions of \MF\ it says,
for example, `\.{(preloaded base=PLAIN 84.2.29)}', showing the year,
month, and day that the base file was created. We have $\\{base\_ident}=0$
before \MF's tables are loaded.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{base\_ident}: \37\\{str\_number};\par
\fi

\M788. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{base\_ident}\K0$;\par
\fi

\M789. \P$\X170:Initialize table entries (done by \.{INIMF} only)\X\mathrel{+}%
\S$\6
$\\{base\_ident}\K\.{"\ (INIMF)"}$;\par
\fi

\M790. \P$\X790:Declare action procedures for use by \\{do\_statement}\X\S$\6
\&{init} \37\&{procedure}\1\  \37\\{store\_base\_file};\6
\4\&{label} \37$\\{found1},\39\\{found2},\39\\{done1},\39\\{done2}$;\6
\4\&{var} \37$\|j,\39\|k,\39\|l$: \37\\{integer};\C{all-purpose indices}\6
$\|p,\39\|q$: \37\\{pointer};\C{all-purpose pointers}\6
\|x: \37\\{integer};\C{something to dump}\6
\|w: \37\\{four\_quarters};\C{four ASCII codes}\2\6
\&{begin} \37\X792:If dumping is not allowed, abort\X;\6
\X807:Create the \\{base\_ident}, open the base file, and inform the user that
dumping has begun\X;\6
\X795:Dump constants for consistency check\X;\6
\X797:Dump the string pool\X;\6
\X799:Dump the dynamic memory\X;\6
\X801:Dump the table of equivalents\X;\6
\X803:Dump the hash table\X;\6
\X805:Dump a couple more things and the closing check word\X;\6
\X808:Close the base file\X;\6
\&{end};\6
\&{tini}\par
\U section~778.\fi

\M791. Corresponding to the procedure that dumps a base file, we have a
function
that reads one in. The function returns \\{false} if the dumped base is
incompatible with the present \MF\ table sizes, etc.

\Y\P\D \37$\\{off\_base}=6666$\C{go here if the base file is unacceptable}\par
\P\D \37$\\{too\_small}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'---!\ Must\ increase\ the\ \'},\39\#)$;\5
\&{goto} \37\\{off\_base};\6
\&{end}\2\par
\Y\P\hbox{\4}\X614:Declare the function called \\{open\_base\_file}\X\6
\4\&{function}\1\  \37\\{load\_base\_file}: \37\\{boolean};\6
\4\&{label} \37$\\{off\_base},\39\\{exit}$;\6
\4\&{var} \37$\|j,\39\|k$: \37\\{integer};\C{all-purpose indices}\6
$\|p,\39\|q$: \37\\{pointer};\C{all-purpose pointers}\6
\|x: \37\\{integer};\C{something undumped}\6
\|w: \37\\{four\_quarters};\C{four ASCII codes}\2\6
\&{begin} \37\X796:Undump constants for consistency check\X;\6
\X798:Undump the string pool\X;\6
\X800:Undump the dynamic memory\X;\6
\X802:Undump the table of equivalents\X;\6
\X804:Undump the hash table\X;\6
\X806:Undump a couple more things and the closing check word\X;\6
$\\{load\_base\_file}\K\\{true}$;\5
\&{return};\C{it worked!}\6
\4\\{off\_base}: \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'(Fatal\ base\ file\ error;\ I\'}\.{\'m\ stymied)\'})$;\5
$\\{load\_base\_file}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M792. The user is not allowed to dump a base file unless $\\{save\_ptr}=%
\\{null}$.

\Y\P$\4\X792:If dumping is not allowed, abort\X\S$\6
\&{if} $\\{save\_ptr}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ dump\ inside\ a\ group"})$;\5
$\\{help1}(\.{"\`begingroup...dump\'\ is\ a\ no-no."})$;\5
\\{succumb};\6
\&{end}\2\par
\U section~790.\fi

\M793. Base files consist of \\{memory\_word} items, and we use the following
macros to dump words of different types:

\Y\P\D \37$\\{dump\_wd}(\#)\S$\1\6
\&{begin} \37$\\{base\_file}\↑\K\#$;\5
$\\{put}(\\{base\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_int}(\#)\S$\1\6
\&{begin} \37$\\{base\_file}\↑.\\{int}\K\#$;\5
$\\{put}(\\{base\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_hh}(\#)\S$\1\6
\&{begin} \37$\\{base\_file}\↑.\\{hh}\K\#$;\5
$\\{put}(\\{base\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_qqqq}(\#)\S$\1\6
\&{begin} \37$\\{base\_file}\↑.\\{qqqq}\K\#$;\5
$\\{put}(\\{base\_file})$;\ \&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{base\_file}: \37\\{word\_file};\C{for input or output of base information}%
\par
\fi

\M794. The inverse macros are slightly more complicated, since we need to check
the range of the values we are reading in. We say `$\\{undump}(\|a)(\|b)(\|x)$'
to
read an integer value \|x that is supposed to be in the range $\|a\L\|x\L\|b$.

\Y\P\D \37$\\{undump\_wd}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{base\_file})$;\5
$\#\K\\{base\_file}\↑$;\ \&{end}\2\par
\P\D \37$\\{undump\_int}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{base\_file})$;\5
$\#\K\\{base\_file}\↑.\\{int}$;\ \&{end}\2\par
\P\D \37$\\{undump\_hh}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{base\_file})$;\5
$\#\K\\{base\_file}\↑.\\{hh}$;\ \&{end}\2\par
\P\D \37$\\{undump\_qqqq}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{base\_file})$;\5
$\#\K\\{base\_file}\↑.\\{qqqq}$;\ \&{end}\2\par
\P\D \37$\\{undump\_end\_end}(\#)\S\#\K\|x$;\ \&{end} \par
\P\D $\\{undump\_end}(\#)\S(\|x>\#)$ \&{then} \&{goto} \37\\{off\_base}\ %
\&{else} \37\\{undump\_end\_end}\par
\P\D $\\{undump}(\#)\S$ \6
\&{begin} \37$\\{undump\_int}(\|x)$;  \6
\&{if} $(\|x<\#)\V\\{undump\_end}$\par
\P\D \37$\\{undump\_size\_end\_end}(\#)\S\\{too\_small}(\#)$\ \&{else} \37%
\\{undump\_end\_end}\par
\P\D \37$\\{undump\_size\_end}(\#)\S$\1\6
\&{if} $\|x>\#$ \1\&{then}\5
\\{undump\_size\_end\_end}\2\2\par
\P\D $\\{undump\_size}(\#)\S$ \6
\&{begin} \37$\\{undump\_int}(\|x)$;\6
\&{if} $\|x<\#$ \1\&{then}\5
\&{goto} \37\\{off\_base};\2\6
\\{undump\_size\_end}\par
\fi

\M795. The next few sections of the program should make it clear how we use the
dump/undump macros.

\Y\P$\4\X795:Dump constants for consistency check\X\S$\6
$\\{dump\_int}(\))$;\6
$\\{dump\_int}(\\{hi\_mem\_base})$;\6
$\\{dump\_int}(\\{hash\_size})$;\6
$\\{dump\_int}(\\{hash\_prime})$\par
\U section~790.\fi

\M796. Sections of a \.{WEB} program that are ``commented out'' still
contribute
strings to the string pool; therefore \.{INIMF} and \MF\ will have
the same strings. (And it is, of course, a good thing that they do.)

\Y\P$\4\X796:Undump constants for consistency check\X\S$\6
$\|x\K\\{base\_file}\↑.\\{int}$;\6
\&{if} $\|x\I\)$ \1\&{then}\5
\&{goto} \37\\{off\_base};\C{check that strings are the same}\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{hi\_mem\_base}$ \1\&{then}\5
\&{goto} \37\\{off\_base};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{hash\_size}$ \1\&{then}\5
\&{goto} \37\\{off\_base};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{hash\_prime}$ \1\&{then}\5
\&{goto} \37\\{off\_base}\2\par
\U section~791.\fi

\M797. \P\D \37$\\{dump\_four\_ASCII}\S\|w.\\{b0}\K\\{str\_pool}[\|k]$;\5
$\|w.\\{b1}\K\\{str\_pool}[\|k+1]$;\5
$\|w.\\{b2}\K\\{str\_pool}[\|k+2]$;\5
$\|w.\\{b3}\K\\{str\_pool}[\|k+3]$;\5
$\\{dump\_qqqq}(\|w)$\par
\Y\P$\4\X797:Dump the string pool\X\S$\6
$\\{dump\_int}(\\{pool\_ptr})$;\5
$\\{dump\_int}(\\{str\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{str\_ptr}$ \1\&{do}\5
$\\{dump\_int}(\\{str\_start}[\|k])$;\2\6
$\|k\K0$;\6
\&{while} $\|k+4<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37\\{dump\_four\_ASCII};\5
$\|k\K\|k+4$;\6
\&{end};\2\6
$\|k\K\\{pool\_ptr}-4$;\5
\\{dump\_four\_ASCII};\5
\\{print\_ln};\5
$\\{print\_int}(\\{str\_ptr})$;\5
$\\{print}(\.{"\ strings\ of\ total\ length\ "})$;\5
$\\{print\_int}(\\{pool\_ptr})$\par
\U section~790.\fi

\M798. \P\D \37$\\{undump\_four\_ASCII}\S\\{undump\_qqqq}(\|w)$;\5
$\\{str\_pool}[\|k]\K\|w.\\{b0}$;\5
$\\{str\_pool}[\|k+1]\K\|w.\\{b1}$;\5
$\\{str\_pool}[\|k+2]\K\|w.\\{b2}$;\5
$\\{str\_pool}[\|k+3]\K\|w.\\{b3}$\par
\Y\P$\4\X798:Undump the string pool\X\S$\6
$\\{undump\_size}(0)(\\{pool\_size})(\.{\'string\ pool\ size\'})(\\{pool%
\_ptr})$;\5
$\\{undump\_size}(0)(\\{max\_strings})(\.{\'max\ strings\'})(\\{str\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{str\_ptr}$ \1\&{do}\5
$\\{undump}(0)(\\{pool\_ptr})(\\{str\_start}[\|k])$;\2\6
$\|k\K0$;\6
\&{while} $\|k+4<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37\\{undump\_four\_ASCII};\5
$\|k\K\|k+4$;\6
\&{end};\2\6
$\|k\K\\{pool\_ptr}-4$;\5
\\{undump\_four\_ASCII}\par
\U section~791.\fi

\M799. By sorting the list of available spaces in the variable-size portion of
\\{mem}, we are usually able to get by without having to dump very much
of the dynamic memory.

We recompute \\{var\_used} and \\{dyn\_used}, so that \.{INIMF} dumps valid
information even when it has not been gathering statistics.

\Y\P$\4\X799:Dump the dynamic memory\X\S$\6
\\{sort\_avail};\5
$\\{var\_used}\K0$;\5
$\\{dump\_int}(\\{rover})$;\5
$\|p\K\\{mem\_base}$;\5
$\|q\K\\{rover}$;\5
$\|x\K0$;\6
\1\&{repeat} \37\&{for} $\|k\K\|p\mathrel{\&{to}}\|q+1$ \1\&{do}\5
$\\{dump\_wd}(\\{mem}[\|k])$;\2\6
$\|x\K\|x+\|q+2-\|p$;\5
$\\{var\_used}\K\\{var\_used}+\|q-\|p$;\5
$\|p\K\|q+\\{node\_size}(\|q)$;\5
$\|q\K\\{rlink}(\|q)$;\6
\4\&{until}\5
$\|q=\\{rover}$;\2\6
$\\{var\_used}\K\\{var\_used}+\\{hi\_mem\_base}-\|p$;\5
$\\{dyn\_used}\K\\{mem\_end}+1-\\{hi\_mem\_base}$;\6
$\\{dump\_int}(\\{mem\_end})$;\5
$\\{dump\_int}(\\{avail})$;\6
\&{for} $\|k\K\|p\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{dump\_wd}(\\{mem}[\|k])$;\2\6
$\|x\K\|x+\\{mem\_end}+1-\|p$;\5
$\|p\K\\{avail}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{dyn\_used})$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{dump\_int}(\\{var\_used})$;\5
$\\{dump\_int}(\\{dyn\_used})$;\5
\\{print\_ln};\5
$\\{print\_int}(\|x)$;\5
$\\{print}(\.{"\ memory\ locations\ dumped;\ current\ usage\ is\ "})$;\5
$\\{print\_int}(\\{var\_used})$;\5
$\\{print\_char}(\.{"\&"})$;\5
$\\{print\_int}(\\{dyn\_used})$\par
\U section~790.\fi

\M800. \P$\X800:Undump the dynamic memory\X\S$\6
$\\{undump}(\\{min\_halfword})(\\{hi\_mem\_base})(\\{rover})$;\5
$\|p\K\\{mem\_base}$;\5
$\|q\K\\{rover}$;\5
$\|x\K0$;\6
\1\&{repeat} \37\&{for} $\|k\K\|p\mathrel{\&{to}}\|q+1$ \1\&{do}\5
$\\{undump\_wd}(\\{mem}[\|k])$;\2\6
$\|p\K\|q+\\{node\_size}(\|q)$;\6
\&{if} $(\|p>\\{hi\_mem\_base})\V((\|q\G\\{rlink}(\|q))\W(\\{rlink}(\|q)\I%
\\{rover}))$ \1\&{then}\5
\&{goto} \37\\{off\_base};\2\6
$\|q\K\\{rlink}(\|q)$;\6
\4\&{until}\5
$\|q=\\{rover}$;\2\6
$\\{undump\_size}(\\{hi\_mem\_base})(\\{mem\_max})(\.{\'mem\ max\'})(\\{mem%
\_end})$;\5
$\\{undump}(\\{null})(\\{mem\_end})(\\{avail})$;\6
\&{for} $\|k\K\|p\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{undump\_wd}(\\{mem}[\|k])$;\2\6
$\\{undump\_int}(\\{var\_used})$;\5
$\\{undump\_int}(\\{dyn\_used})$;\5
$\\{max\_var\_used}\K\\{var\_used}$\par
\U section~791.\fi

\M801. \P$\X801:Dump the table of equivalents\X\S$\6
\\{FIXTHIS}\par
\U section~790.\fi

\M802. \P$\X802:Undump the table of equivalents\X\S$\6
\\{FIXTHIS}\par
\U section~791.\fi

\M803. A different scheme is used to compress the hash table, since its lower
region is usually sparse. When $\\{text}(\|p)\I0$ for $\|p\L\\{hash\_used}$, we
output
two words, \|p and $\\{hash}[\|p]$. The hash table is, of course, densely
packed
for $\|p\G\\{hash\_used}$, so the remaining entries are output in a block.

\Y\P$\4\X803:Dump the hash table\X\S$\6
$\\{dump\_int}(\\{hash\_used})$;\5
$\\{cs\_count}\K\\{effective\_hash\_size}-\\{hash\_used}$;\6
\&{for} $\|p\K\\{hash\_base}\mathrel{\&{to}}\\{hash\_used}$ \1\&{do}\6
\&{if} $\\{text}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{dump\_int}(\|p)$;\5
$\\{dump\_hh}(\\{hash}[\|p])$;\5
$\\{incr}(\\{cs\_count})$;\6
\&{end};\2\2\6
\&{for} $\|p\K\\{hash\_used}+1\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{dump\_hh}(\\{hash}[\|p])$;\2\6
$\\{dump\_int}(\\{cs\_count})$;\6
\\{print\_ln};\5
$\\{print\_int}(\\{cs\_count})$;\5
$\\{print}(\.{"\ multiletter\ control\ sequences"})$\par
\U section~790.\fi

\M804. \P$\X804:Undump the hash table\X\S$\6
$\\{undump}(\\{hash\_base})(\\{effective\_hash\_size}+1)(\\{hash\_used})$;\5
$\|p\K\\{hash\_base}-1$;\6
\1\&{repeat} \37$\\{undump}(\|p+1)(\\{hash\_used})(\|p)$;\5
$\\{undump\_hh}(\\{hash}[\|p])$;\6
\4\&{until}\5
$\|p=\\{hash\_used}$;\2\6
\&{for} $\|p\K\\{hash\_used}+1\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{undump\_hh}(\\{hash}[\|p])$;\2\6
$\\{undump\_int}(\\{cs\_count})$\par
\U section~791.\fi

\M805. We have already printed a lot of statistics, so we set $\\{tracing%
\_stats}\K0$
to prevent them appearing again.

\Y\P$\4\X805:Dump a couple more things and the closing check word\X\S$\6
$\\{dump\_int}(\\{interaction})$;\5
$\\{dump\_int}(\\{base\_ident})$;\5
$\\{dump\_int}(69069)$;\5
$\\{tracing\_stats}\K0$\par
\U section~790.\fi

\M806. \P$\X806:Undump a couple more things and the closing check word\X\S$\6
$\\{undump}(\\{batch\_mode})(\\{error\_stop\_mode})(\\{interaction})$;\5
$\\{undump}(0)(\\{str\_ptr})(\\{base\_ident})$;\5
$\\{undump\_int}(\|x)$;\6
\&{if} $(\|x\I69069)\V\\{eof}(\\{base\_file})$ \1\&{then}\5
\&{goto} \37\\{off\_base}\2\par
\U section~791.\fi

\M807. \P$\X807:Create the \\{base\_ident}, open the base file, and inform the
user that dumping has begun\X\S$\6
$\\{selector}\K\\{new\_string}$;\5
$\\{print}(\.{"\ (preloaded\ base="})$;\5
$\\{print}(\\{job\_name})$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\\{year}\mathbin{\&{mod}}100)$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_int}(\\{month})$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_int}(\\{day})$;\5
$\\{print\_char}(\.{")"})$;\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{selector}\K\\{log\_only}$\6
\4\&{else} $\\{selector}\K\\{term\_and\_log}$;\2\6
$\\{str\_room}(1)$;\5
$\\{base\_ident}\K\\{make\_string}$;\5
$\\{pack\_job\_name}(\.{".base"})$;\6
\&{while} $\R\\{w\_open\_out}(\\{base\_file})$ \1\&{do}\5
$\\{prompt\_file\_name}(\.{"base\ file\ name"},\39\.{".base"})$;\2\6
$\\{print\_nl}(\.{"Beginning\ to\ dump\ on\ file\ "})$;\5
$\\{print}(\\{w\_make\_name\_string}(\\{base\_file}))$;\5
\\{flush\_string};\5
$\\{print\_nl}(\\{base\_ident})$\par
\U section~790.\fi

\M808. \P$\X808:Close the base file\X\S$\6
$\\{w\_close}(\\{base\_file})$\par
\U section~790.\fi

\N809.  \[xx] The main program.
This is it: the part of \MF\ that executes all those procedures we have
written.

Well---almost. Let's leave space for a few more routines that we may
have forgotten.

\Y\P\X812:Last-minute procedures\X\par
\fi

\M810. We have noted that there are two versions of \MF84. One, called %
\.{INIMF},
has to be run first; it initializes everything from scratch, without
reading a base file, and it has the capability of dumping a base file.
The other one is called `\.{VIRMF}'; it is a ``virgin'' program that needs
to input a base file in order to get started. \.{VIRMF} typically has
a bit more memory capacity than \.{INIMF}, because it does not need the
space consumed by the dumping/undumping routines and the numerous calls on
\\{primitive}, etc.

The \.{VIRMF} program cannot read a base file instantaneously, of course;
the best implementations therefore allow for production versions of \MF\ that
not only avoid the loading routine for \PASCAL\ object code, they also have
a base file pre-loaded. This is impossible to do if we stick to standard
\PASCAL, but there is a simple way to fool many systems into avoiding the
initialization, as follows.\quad(1)~We declare a global integer variable
called \\{ready\_already}. The probability is negligible that this
variable holds any particular value like 314159 when \.{VIRMF} is first
loaded.\quad(2)~After we have read in a base file and initialized
everything, we set $\\{ready\_already}\K314159$.\quad(3)~Soon \.{VIRMF}
will print `\.*', waiting for the first input; and at this point we
interrupt the program and save its core image in some form that the
operating system can reload speedily.\quad(4)~When that core image is
activated, the program starts again at the beginning; but now
$\\{ready\_already}=314159$ and all the other global variables have
their initial values too. The former chastity has vanished!

In other words, if we allow ourselves to test the condition
$\\{ready\_already}=314159$, before \\{ready\_already} has been
assigned a value, we can avoid the lengthy initialization. Dirty tricks
rarely pay off so handsomely.

On systems that allow such preloading, the standard program called \.{MF}
should be the one that has \.{PLAIN} base preloaded, since that agrees
with {\tenss The \MF book}. Other versions, e.g., \.{CMBASE}, should also
be provided for commonly used bases.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{ready\_already}: \37\\{integer};\C{a sacrifice of purity for economy}\par
\fi

\M811. Now this is really it: \MF\ starts and ends here.

The initial test involving \\{ready\_already} should be deleted if the
\PASCAL\ runtime system is smart enough to detect such a ``mistake.''

\Y\P\&{begin} \37\C{\\{start\_here}}\6
$\\{history}\K\\{fatal\_error\_stop}$;\C{in case we quit during initialization}%
\6
\\{t\_open\_out};\C{open the terminal for output}\6
\&{if} $\\{ready\_already}=314159$ \1\&{then}\5
\&{goto} \37\\{start\_of\_MF};\2\6
\\{initialize};\C{set global variables to their starting values}\6
\X14:Check the ``constant'' values for consistency\X\6
\&{if} $\\{bad}>0$ \1\&{then}\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{wterm}(\.{\'Ouch---my\ internal\ constants\ have\ been\'},\39\.{\'\
clobbered!---case\ \'},\39\\{bad}:1)$;\5
\&{goto} \37\\{final\_end};\6
\&{end};\2\6
\&{init} \37\&{if} $\R\\{get\_strings\_started}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
\\{init\_prim};\C{call \\{primitive} for each primitive}\6
\&{tini}\6
$\\{ready\_already}\K314159$;\6
\4\\{start\_of\_MF}: \37\X55:Initialize the output routines\X;\6
\X816:Get the first line of input and prepare to start\X;\6
$\\{init\_str\_ptr}\K\\{str\_ptr}$;\5
$\\{init\_pool\_ptr}\K\\{pool\_ptr}$;\6
$\\{history}\K\\{spotless}$;\C{ready to go!}\6
\\{main\_control};\C{come to life}\6
\\{final\_cleanup};\C{prepare for death}\6
\4\\{end\_of\_MF}: \37\\{close\_files\_and\_terminate};\6
\4\\{final\_end}: \37$\\{ready\_already}\K0$;\6
\&{end}.\par
\fi

\M812. Here we do whatever is needed to complete \MF's job gracefully on the
local operating system. The code here might come into play after a fatal
error; it must therefore consist entirely of ``safe'' operations that
cannot produce error messages. For example, it would be a mistake to call
\\{str\_room} or \\{make\_string} at this time, because a call on \\{overflow}
might lead to an infinite loop.

\Y\P$\4\X812:Last-minute procedures\X\S$\6
\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\6
\4\&{var} \37\|k: \37\\{integer};\C{all-purpose index}\2\6
\&{begin} \37\&{stat} \37\&{if} $\\{tracing\_stats}>0$ \1\&{then}\5
\X813:Output statistics about this job\X;\2\ \&{tats}\6
\\{wake\_up\_terminal};\5
\X665:Finish the \.{GF} file\X;\6
\&{if} $\\{job\_name}>0$ \1\&{then}\6
\&{begin} \37\\{wlog\_cr};\5
$\\{a\_close}(\\{log\_file})$;\5
$\\{selector}\K\\{selector}-2$;\6
\&{if} $\\{selector}=\\{term\_only}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Transcript\ written\ on\ "})$;\5
$\\{print}(\\{log\_name})$;\5
$\\{print\_char}(\.{"."})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\A sections~814, 815, and~817.
\U section~809.\fi

\M813. The present section goes directly to the log file instead of using
\\{print} commands, because there's no need for these strings to take
up \\{str\_pool} memory when a non- \&{stat}  version of \MF\ is being used.

\Y\P$\4\X813:Output statistics about this job\X\S$\6
\&{if} $\\{job\_name}>0$ \1\&{then}\C{the log file is open}\6
\&{begin} \37$\\{wlog\_ln}(\.{\'\ \'})$;\5
$\\{wlog\_ln}(\.{\'Here\ is\ how\ much\ of\ METAFONT\'}\.{\'s\ memory\'},\39\.{%
\'\ you\ used:\'})$;\5
$\\{wlog}(\.{\'\ \'},\39\\{str\_ptr}-\\{init\_str\_ptr}:1,\39\.{\'\ string%
\'})$;\6
\&{if} $\\{str\_ptr}\I\\{init\_str\_ptr}+1$ \1\&{then}\5
$\\{wlog}(\.{\'s\'})$;\2\6
$\\{wlog\_ln}(\.{\'\ out\ of\ \'},\39\\{max\_strings}-\\{init\_str\_ptr}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{pool\_ptr}-\\{init\_pool\_ptr}:1,\39\.{\'\
string\ characters\ out\ of\ \'},\39\\{pool\_size}-\\{init\_pool\_ptr}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{max\_var\_used}:1,\39\.{\'\&\'},\39\\{mem%
\_end}+1-\\{hi\_mem\_base}:1,\39\30\.{\'\ words\ of\ memory\ out\ of\ \'},\39%
\\{hi\_mem\_base}-\\{mem\_base}:1,\39\.{\'\&\'},\39\\{mem\_max}+1-\\{hi\_mem%
\_base}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{st\_count}:1,\39\.{\'\ multiletter\ control\
sequences\ out\ of\ \'},\39\\{hash\_size}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{max\_in\_stack}:1,\39\.{\'i,\'},\39\\{max\_nest%
\_stack}:1,\39\.{\'n,\'},\39\30\\{max\_param\_stack}:1,\39\.{\'p,\'},\39\30%
\\{max\_buf\_stack}+1:1,\39\.{\'b\ stack\ positions\ out\ of\ \'},\39\30%
\\{stack\_size}:1,\39\.{\'i,\'},\39\\{nest\_size}:1,\39\.{\'n,\'},\39\\{param%
\_size}:1,\39\.{\'p,\'},\39\\{buf\_size}:1,\39\.{\'b,\'})$;\6
\&{end}\2\par
\U section~812.\fi

\M814. We get to the \\{final\_cleanup} routine when \&{end} or \&{dump} has
been scanned and \\{its\_all\_over}.

\Y\P$\4\X812:Last-minute procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{final\_cleanup};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|c: \37\\{small\_number};\C{0 for \&{end}, 1 for \&{dump}}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{while} $\\{cond\_ptr}\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{print\_nl}(\.{"("})$;\5
$\\{print\_esc}(\.{"end\ occurred\ "})$;\5
$\\{print}(\.{"when\ "})$;\5
$\\{print\_cmd\_mod}(\\{if\_test},\39\\{cur\_if})$;\6
\&{if} $\\{if\_line}\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ on\ line\ "})$;\5
$\\{print\_int}(\\{if\_line})$;\6
\&{end};\2\6
$\\{print}(\.{"\ was\ incomplete)"})$;\5
$\\{if\_line}\K\\{if\_line\_field}(\\{cond\_ptr})$;\5
$\\{cur\_if}\K\\{subtype}(\\{cond\_ptr})$;\5
$\\{cond\_ptr}\K\\{link}(\\{cond\_ptr})$;\6
\&{end};\2\6
\&{if} $\\{history}\I\\{spotless}$ \1\&{then}\6
\&{if} $((\\{history}=\\{warning\_issued})\V(\\{interaction}<\\{error\_stop%
\_mode}))$ \1\&{then}\6
\&{if} $\\{selector}=\\{term\_and\_log}$ \1\&{then}\6
\&{begin} \37$\\{selector}\K\\{term\_only}$;\5
$\\{print\_nl}(\.{"(see\ the\ transcript\ file\ for\ additional\
information)"})$;\5
$\\{selector}\K\\{term\_and\_log}$;\6
\&{end};\2\2\2\6
\&{if} $\|c=1$ \1\&{then}\6
\&{begin} \37\&{init} \37\\{store\_base\_file};\5
\&{return};\ \&{tini}\6
$\\{print\_nl}(\.{"(dump\ is\ performed\ only\ by\ INIMF)"})$;\5
\&{return};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M815. \P$\X812:Last-minute procedures\X\mathrel{+}\S$\6
\&{init} \37\&{procedure}\1\  \37\\{init\_prim};\C{initialize all the
primitives}\2\6
\&{begin} \37\X184:Put each of \MF's primitives into the hash table\X;\6
\&{end};\6
\&{tini}\par
\fi

\M816. When we begin the following code, \MF's tables may still contain
garbage;
the strings might not even be present. Thus we must proceed cautiously to get
bootstrapped in.

But when we finish this part of the program, \MF\ is ready to call on the
\\{main\_control} routine to do its work.

\Y\P$\4\X816:Get the first line of input and prepare to start\X\S$\6
\&{begin} \37\X526:Initialize the input routines\X;\6
\&{if} $(\\{base\_ident}=0)\V(\\{buffer}[\\{loc}]=\.{"\&"})$ \1\&{then}\6
\&{begin} \37\&{if} $\\{base\_ident}\I0$ \1\&{then}\5
\\{initialize};\C{erase preloaded base}\2\6
\&{if} $\R\\{open\_base\_file}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
\&{if} $\R\\{load\_base\_file}$ \1\&{then}\6
\&{begin} \37$\\{w\_close}(\\{base\_file})$;\5
\&{goto} \37\\{final\_end};\6
\&{end};\2\6
$\\{w\_close}(\\{base\_file})$;\6
\&{while} $(\\{loc}<\\{limit})\W(\\{buffer}[\\{loc}]=\.{"\ "})$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{end};\2\6
$\\{buffer}[\\{limit}]\K\.{"\%"}$;\5
\\{fix\_date\_and\_time};\6
\X69:Initialize the print \\{selector} based on \\{interaction}\X;\6
\&{if} $\\{buffer}[\\{log}]\I\.{"\\"}$ \1\&{then}\5
\\{start\_input};\C{\&{input} assumed}\2\6
\&{end}\par
\U section~811.\fi

\N817.  \[xx] Debugging.
Once \MF\ is working, it should be possible to diagnose most errors with
the \.{show} commands and other diagnostic features. But for the initial
stages of debugging, and for the revelation of really deep mysteries, you
can compile \MF\ with a few more aids including the \PASCAL\ runtime
checks and its debugger. An additional routine called \\{debug\_help}
will also come into play when you type `\.D' after an error message;
\\{debug\_help} also occurs just before a fatal error causes \MF\ to succumb.

The interface to \\{debug\_help} is primitive, but it is good enough when used
with a \PASCAL\ debugger that allows you to set breakpoints and to read
variables and change their values. After getting the prompt `\.{debug \#}', you
type either a negative number (this exits \\{debug\_help}), or zero (this
goes to a location where you can set a breakpoint, thereby entering into
dialog with the \PASCAL\ debugger), or a positive number \|m followed by
an argument \|n. The meaning of \|m and \|n will be clear from the
program below. (If $\|m=13$, there is an additional argument, \|l.)

\Y\P\D \37$\\{breakpoint}=888$\C{place where a breakpoint is desirable}\par
\Y\P$\4\X812:Last-minute procedures\X\mathrel{+}\S$\6
\&{debug} \37\&{procedure}\1\  \37\\{debug\_help};\C{routine to display various
things}\6
\4\&{label} \37$\\{breakpoint},\39\\{exit}$;\6
\4\&{var} \37$\|k,\39\|l,\39\|m,\39\|n$: \37\\{integer};\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{print\_nl}(\.{"debug\ \#\ (-1\ to\ exit):"})$;\5
\\{update\_terminal};\5
$\\{read}(\\{term\_in},\39\|m)$;\6
\&{if} $\|m<0$ \1\&{then}\5
\&{return}\6
\4\&{else} \&{if} $\|m=0$ \1\&{then}\6
\&{begin} \37\&{goto} \37\\{breakpoint};\5
\]\C{go to every label at least once}\6
\4\\{breakpoint}: \37$\|m\K0$;\5
$\B\.{\'BREAKPOINT\'}\T\]$\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{read}(\\{term\_in},\39\|n)$;\6
\&{case} $\|m$ \1\&{of}\6
\hbox{\4}\X818:Numbered cases for \\{debug\_help}\X\6
\4\&{othercases} \37$\\{print}(\.{"?"})$\2\6
\&{endcases};\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\6
\&{gubed}\par
\fi

\M818. \P$\X818:Numbered cases for \\{debug\_help}\X\S$\6
\41: \37$\\{print\_word}(\\{mem}[\|n])$;\C{display $\\{mem}[\|n]$ in all forms}%
\6
\42: \37$\\{print\_int}(\\{info}(\|n))$;\6
\43: \37$\\{print\_int}(\\{link}(\|n))$;\6
\44: \37$\\{print\_word}(\\{eqtb}[\|n])$;\6
\46: \37$\\{print\_int}(\\{internal}[\|n])$;\6
\49: \37$\\{show\_token\_list}(\|n,\39\\{null},\391000)$;\6
\410: \37$\\{print}(\|n)$;\6
\411: \37$\\{check\_mem}(\|n>0)$;\C{check wellformedness; print new busy
locations if $\|n>0$}\6
\412: \37$\\{search\_mem}(\|n)$;\C{look for pointers to \|n}\6
\413: \37\&{begin} \37$\\{read}(\\{term\_in},\39\|l)$;\5
$\\{print\_cmd\_mod}(\|n,\39\|l)$;\6
\&{end};\6
\414: \37\&{for} $\|k\K0\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\6
\416: \37$\\{panicking}\K\R\\{panicking}$;\par
\U section~817.\fi

\N819.  \[xx] System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \MF\ work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the published program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.
\fi

\N820.  \[xx] Index.
Here is where you can find all uses of each identifier in the program,
with underlined entries pointing to where the identifier was defined.
If the identifier is only one letter long, however, you get to see only
the underlined entries. All references are to section numbers instead of
page numbers.

This index also lists error messages and other aspects of the program
that you might want to look up some day. For example, the entry
for ``system dependencies'' lists all sections that should receive
special attention from people who are installing \MF\ in a new
operating environment. A list of various things that can't happen appears
under ``this can't happen''. Approximately 40 sections are listed under
``inner loop''; these account for about 60\% of \MF's running time,
exclusive of input and output.
\fi


\inx
\:\.{**}, 37, 624.
\:\9{*\_}{\.{*} primitive}, \[751].
\:\9{++\_}{\.{++} primitive}, \[751].
\:\9{+\_}{\.{+} primitive}, \[751].
\:\9{,\_}{\&{,} primitive}, \[199].
\:\.{->}, 215.
\:\9{-\_}{\.{-} primitive}, \[751].
\:\9{..\_}{\.{..} primitive}, \[199].
\:\9{/\_}{\.{/} primitive}, \[199], \[751].
\:\9{:=\_}{\.{:=} primitive}, \[199].
\:\9{:\_}{\.{:} primitive}, \[199].
\:\9{;\_}{\&{;} primitive}, \[199].
\:\9{<=\_}{\.{<=} primitive}, \[751].
\:\9{<>\_}{\.{<>} primitive}, \[751].
\:\9{<\_}{\.{<} primitive}, \[751].
\:\.{=>}, 547.
\:\9{=\_}{\.{=} primitive}, \[199], \[751].
\:\9{>=\_}{\.{>=} primitive}, \[751].
\:\9{>\_}{\.{>} primitive}, \[751].
\:\.{??}, 271, 273.
\:\.{???}, 59.
\:\9{[\_}{\.{[} primitive}, \[199].
\:\.{\#}, 817.
\:\9{\#\AT!\_}{\.{\#\AT!} primitive}, \[553].
\:\9{\&\_}{\.{\&} primitive}, \[199], \[751].
\:\9{\AT!\#\_}{\.{\AT!\#} primitive}, \[553].
\:\9{\AT!\_}{\.{\AT!} primitive}, \[553].
\:\9{\char`\{\_}{\.{\char`\}} primitive}, \[199].
\:\9{\char`\}\_}{\.{\char`\}} primitive}, \[199].
\:\9{]\_}{\.{]} primitive}, \[199].
\:\|{a}, \[47], \[98], \[113], \[120], \[325], \[358], \[476], \[577], \[608], %
\[609], \[613], \[650].
\:\\{a\_close}, \[28], 51, 524, 812.
\:\\{a\_make\_name\_string}, \[615], 624, 627.
\:\\{a\_open\_in}, \[27], 51, 627.
\:\\{a\_open\_out}, \[27], 624.
\:\\{a\_tension}, \[302].
\:\\{aa}, \[292], 294, 296, 297, 306.
\:\\{ab\_geq\_cd}, \[113], 145, 321, 418, 437, 773, 776.
\:\\{abort\_find}, \[227], 228.
\:\\{abort\_path}, 735, 736.
\:\\{abs}, 64, 120, 143, 145, 241, 242, 246, 247, 248, 249, 253, 254, 255, 260,
325, 331, 366, 370, 393, 395, 431, 433, 437, 463, 466, 655, 695, 759, 773, 776.
\:\\{absorbing}, 583.
\:\\{acc}, \[108], \[292], 296.
\:\\{add\_or\_subtract}, 764, \[765].
\:\\{add\_ref}, \[212], 575, 699, 718, 722, 734.
\:\9{add\_to\_}{\&{addto} primitive}, \[199].
\:\\{add\_token\_ref}, 518.
\:\\{alpha}, \[302], \[399], 400, \[462], 463, 464, 466.
\:\\{alpha\_file}, \[25], 27, 28, 31, 32, 50, 54, 501, 615.
\:\\{already\_there}, \[485], 486, 493.
\:\\{ampersand}, \[180], 199, 200, 722, 745, 746, 748, 751, 752.
\:\9{and\_}{\&{and} primitive}, \[199], \[751].
\:\\{and\_command}, \[180], 199, 200, 741, 743, 751, 752.
\:\\{and\_op}, \[182], 751.
\:\\{angle}, \[102], 130, 132, 137, 138, 285, 289, 462.
\:\\{append\_char}, \[42], 48, 52, 58, 195, 536, 606, 615.
\:\\{append\_to\_name}, \[609], 613.
\:\9{arctan\_d\_}{\&{arctand} primitive}, \[751].
\:\\{arctan\_d\_op}, \[182], 751, 760.
\:\\{area\_delimiter}, \[603], 605, 606, 607.
\:\\{arg\_list}, 574, \[575], 576, 578, 579, 580, 581, 584, 585.
\:\\{arith\_error}, \[94], 95, 96, 103, 105, 109, 111, 120, 128, 275, 683.
\:\9{as\_}{\&{as} primitive}, \[199].
\:\\{as\_token}, \[180], 199, 200.
\:{ASCII code}, 17.
\:\\{ASCII\_code}, \[18], 19, 20, 29, 30, 31, 39, 42, 54, 58, 76, 188, 606,
609, 613.
\:\\{assignment}, \[180], 199, 200, 706, 709.
\:\9{at\_}{\&{at} primitive}, \[199].
\:\\{at\_token}, \[180], 199, 200.
\:\\{attr}, 217, \[218], 222, 224, 225, 230.
\:\\{attr\_head}, \[216], 217, 224, 226, 227, 229, 230, 231, 232, 239, 705.
\:\\{attr\_loc}, \[217], 222, 224, 226, 229, 230, 705.
\:\\{attr\_loc\_loc}, \[217], 226, 229.
\:\\{attr\_node\_size}, \[217], 224, 226, 230, 232.
\:\\{avail}, \[154], 156, 157, 158, 170, 175, 799, 800.
\:\.{AVAIL list clobbered...}, 175.
\:\\{ave}, \[401].
\:\\{axis}, \[360], 395, 401, 442, 443, 452, 454.
\:\|{b}, \[120], \[358], \[476], \[488], \[595], \[613], \[650].
\:\\{b\_close}, \[28], 665.
\:\\{b\_make\_name\_string}, \[615], 622.
\:\\{b\_open\_in}, \[27].
\:\\{b\_open\_out}, \[27], 622.
\:\\{b\_tension}, \[302].
\:\\{back\_error}, \[522], 559, 565, 580, 584, 689, 696, 717, 721, 724, 732,
738, 779.
\:\\{back\_expr}, 701, \[702].
\:\\{back\_input}, \[521], 522, 600, 684, 685, 695, 701, 706, 708, 718, 722,
734, 738, 780, 782.
\:\\{back\_list}, \[518], 521, 529.
\:\\{backed\_up}, \[502], 505, 506, 508, 518, 519.
\:\.{BAD}, 207.
\:\\{bad}, \[13], 14, 147, 202, 315, 612, 811.
\:\.{Bad flag...}, 177.
\:\\{bad\_binary}, \[762], 764, 772, 775.
\:\\{bad\_exp}, 683, \[684], 718, 722, 734.
\:\\{bad\_pool}, \[51], 52, 53.
\:\\{bad\_subscript}, 700, \[704], 717.
\:\\{bad\_unary}, 754, \[755], 757, 759, 760.
\:\\{balance}, \[550], 552, \[575], 583.
\:\\{banner}, \[2], 60, 626, 787.
\:\\{base}, 345, 346, 565, 566.
\:\\{base\_area\_length}, \[610], 614.
\:\\{base\_default\_length}, \[610], 612, 613, 614.
\:\\{base\_ext\_length}, \[610], 613, 614.
\:\\{base\_file}, 614, \[793], 794, 796, 806, 807, 808, 816.
\:\\{base\_ident}, 60, 626, \[787], 788, 789, 805, 806, 807, 816.
\:\\{base\_ptr}, 78, 79, \[504], 505, 506, 507.
\:\\{batch\_mode}, \[67], 69, 80, 84, 85, 86, 806, 807.
\:\\{bb}, \[292], 293, 294, 297.
\:\\{bc}, 630, 631, 633.
\:\\{be\_careful}, \[103], 104, \[105], \[109], \[111], 112.
\:\&{begin}, 7, 8, \[252].
\:\\{begin\_a\_group}, 689, \[690].
\:\\{begin\_diagnositic}, 187.
\:\\{begin\_diagnostic}, 70, \[185], 187, 496, 576, 599, 756, 763.
\:\\{begin\_file\_reading}, 72, 81, \[523], 568, 627.
\:\\{begin\_group}, \[180], 199, 200, 683.
\:\9{begin\_group\_}{\&{begingroup} primitive}, \[199].
\:\\{begin\_name}, 602, \[605], 616, 621.
\:\\{begin\_pseudoprint}, \[511], 513, 514.
\:\\{begin\_token\_list}, \[518], 542, 585, 702.
\:\\{beginning}, \[681], 682, 683, 734.
\:\.{Beginning to dump...}, 807.
\:{Bernshte{\u\i}n, Serge{\u\i} Natanovich}, 308.
\:\\{beta}, \[302], \[399], 400, \[462], 463, 464, 466.
\:\9{Bezier}{B\'ezier, Pierre}, 263.
\:\\{big}, \[120].
\:\\{big\_switch}, \[778].
\:{BigEndian order}, \[630].
\:\\{binary\_mac}, 718, \[720], 722, 734.
\:\\{bisect\_ptr}, \[314], 316, 317, 318.
\:\\{bisect\_stack}, \[314].
\:\\{bistack\_size}, \[11], 314, 315.
\:\\{black}, \[473], 476, 485, 487, 488, 492, 493, 640, 641.
\:\\{blank\_line}, \[185].
\:\\{blank\_rectangle}, 472, 474, \[475], 477, 479, 480, 482, 485.
\:\\{boc}, 639, 641, \[642], 643, 658, 659.
\:\\{boolean}, 27, 31, 37, 45, 46, 47, 70, 73, 89, 94, 103, 105, 109, 111, 113,
120, 172, 174, 185, 231, 243, 248, 249, 353, 364, 391, 401, 411, 432, 472, 477,
480, 485, 545, 595, 606, 614, 673, 676, 681, 683, 734, 773, 791.
\:\9{boolean\_}{\&{boolean} primitive}, \[783].
\:\\{boolean\_const}, \[180], 671, 672, 683.
\:\\{boolean\_type}, \[181], 667, 668, 674, 691, 711, 783, 784.
\:\\{bot}, \[636].
\:\\{bot\_row}, \[475], \[480], 482, 485.
\:\9{bounded\_}{\&{bounded} primitive}, \[739].
\:\\{bounded\_code}, \[739], 740, 741.
\:\\{break}, 34.
\:\\{break\_in}, 34.
\:\\{breakpoint}, \[817].
\:\\{buf\_size}, \[11], 30, 31, 65, 147, 510, 523, 533, 547, 614, 620, 624, 813.
\:\\{buffer}, \[30], 31, 36, 37, 45, 65, 77, 81, 82, 194, 195, 196, 198, 499,
500, 510, 513, 533, 535, 536, 538, 539, 544, 546, 547, 568, 613, 614, 616, 620,
621, 624, 628, 816, 818.
\:\\{bypass\_eoln}, \[31].
\:\\{byte\_file}, \[25], 27, 28, 615, 622, 629.
\:\\{b0}, 146, \[149], 150, 216, 263, 635, 636, 797, 798.
\:\\{b1}, 146, \[149], 150, 216, 263, 635, 636, 797, 798.
\:\\{b2}, 146, \[149], 150, 635, 636, 797, 798.
\:\\{b3}, 146, \[149], 150, 635, 636, 797, 798.
\:\|{c}, \[47], \[76], \[182], \[198], \[205], \[358], \[426], \[462], \[475], %
\[476], \[563], \[606], \[609], \[613], \[658], \[683], \[718], \[720], \[722],
\[734], \[753], \[754], \[755], \[761], \[762], \[765], \[814].
\:\.{CAPSULE}, 223.
\:\\{capsule}, \[218], 223, 262, 668, 677, 687, 715, 733.
\:\\{carriage\_return}, \[22], 49, 547.
\:\\{cc}, \[292], 294, 295, 296, 300, 301.
\:\\{cf}, \[108], 303, \[304], 305, 306.
\:\\{change\_if\_limit}, \[594], 595.
\:\\{char}, 19, 26, 610, 624.
\:\9{char\_}{\&{char} primitive}, \[751].
\:\\{char\_class}, \[188], 189, 205, 211, 535, 538, 539.
\:\\{char\_code}, \[183], 184, 658.
\:\9{char\_code\_}{\&{charcode} primitive}, \[184].
\:\\{char\_dp}, \[183], 184.
\:\9{char\_dp\_}{\&{chardp} primitive}, \[184].
\:\\{char\_dw}, \[183], 184, 658.
\:\9{char\_dw\_}{\&{chardw} primitive}, \[184].
\:\\{char\_ht}, \[183], 184.
\:\9{char\_ht\_}{\&{charht} primitive}, \[184].
\:\\{char\_ic}, \[183], 184.
\:\9{char\_ic\_}{\&{charic} primitive}, \[184].
\:\\{char\_info}, 633.
\:\\{char\_info\_word}, 631, \[633], 634.
\:\\{char\_loc}, 643.
\:\\{char\_loc1}, 641, \[642], 665.
\:\\{char\_loc2}, \[641].
\:\\{char\_loc3}, \[641].
\:\\{char\_loc4}, \[641].
\:\\{char\_op}, \[182], 751.
\:\\{char\_ptr}, \[645], 657, 658, 665.
\:\\{char\_wd}, \[183], 184.
\:\9{char\_wd\_}{\&{charwd} primitive}, \[184].
\:{character set dependencies}, 23, 49.
\:{check sum}, 53, 632.
\:\\{check\_arith}, \[96], 275, 753, 754, 761.
\:\\{check\_delimiter}, 565, 686, 687, \[779].
\:\\{check\_equals}, \[559], 560, 563.
\:\\{check\_gf}, \[657].
\:\\{check\_interrupt}, \[89], 519, 535, 685.
\:\\{check\_mem}, 172, \[174], 685, 818.
\:\\{check\_outer\_validity}, \[528], 534, 546.
\:\\{check\_sum}, 665.
\:{Chinese characters}, 630.
\:\\{chopped}, \[364], 366.
\:\\{chr}, 19, 20, 23, 24.
\:\\{chr\_code}, 572, 589.
\:\\{class}, \[205], 208, 209, 211, 535.
\:\\{clear\_arith}, \[96], 683.
\:\\{clear\_for\_error\_prompt}, 72, 77, \[525], 537.
\:\\{clear\_terminal}, \[34], 525, 620.
\:\.{CLOBBERED}, 206.
\:\\{clobbered}, \[174], 175, 176.
\:\\{clockwise}, 390, \[391], 392, 394.
\:\\{close}, 28.
\:\\{close\_files\_and\_terminate}, 72, 75, 811, \[812].
\:\.{CMBASE}, 810.
\:\\{cmd}, \[495], \[496], 751.
\:\\{coef\_bound}, 767.
\:\\{coef\_threshold}, \[243], 246, 247, 248, 249, 773, 776.
\:\\{colon}, \[180], 199, 200.
\:\\{comma}, \[180], 199, 200, 566, 579, 580, 686, 721, 732, 785, 786.
\:\\{common\_ending}, \[15], 241, 595, 597, 683, 738.
\:\\{comp}, \[354], 355.
\:\\{complement}, \[354], 371, 373, 374, 376, 377, 378.
\:\\{concatenate}, \[182], 751.
\:\\{cond\_ptr}, \[586], 587, 592, 593, 594, 595, 597, 814.
\:\\{conditional}, 569, 570, \[595].
\:\\{confusion}, \[88], 103, 165, 222, 224, 241, 472, 475, 476, 594, 660, 674,
753, 754, 761.
\:\\{continue}, \[15], 76, 77, 78, 82, 83, 316, 318, 325, 718, 722, 734, 735.
\:\\{continue\_path}, 735.
\:\.{control?}, 268.
\:\\{controls}, \[180], 199, 200, 738.
\:\9{controls\_}{\&{controls} primitive}, \[199].
\:\\{coord}, 299.
\:\\{coord\_node\_size}, 168, \[264], 275, 414, 420, 424, 737.
\:\\{coords}, \[275].
\:\\{copy\_big\_node}, 711, \[715].
\:\\{copy\_dep\_list}, 711, \[713], 715.
\:\\{copy\_edges}, \[337], 711.
\:\\{copy\_path}, 711.
\:\9{cos\_d\_}{\&{cosd} primitive}, \[751].
\:\\{cos\_d\_op}, \[182], 751, 759.
\:\\{cosine}, \[286], 287, 298, 299, 306.
\:\\{crossing\_point}, \[358], 359, 368, 373, 375, 377, 379, 382, 432, 434, 438.
\:\\{cs}, \[643].
\:\\{cs\_count}, 803, 804.
\:\\{ct}, \[108], 303, \[304], 305, 306.
\:\9{cull\_}{\&{cull} primitive}, \[751].
\:\\{cull\_edges}, \[341].
\:\\{cull\_of}, \[182], 751.
\:\\{cur}, 734.
\:\\{cur\_area}, \[602], 607, 619, 620, 625.
\:\\{cur\_chr}, 591, 592, 595, 597, 600, 814.
\:\\{cur\_cmd}, 82, \[494], 520, 521, 527, 529, 533, 534, 536, 540, 541, 543,
544, 550, 558, 559, 563, 564, 565, 566, 567, 569, 570, 579, 580, 583, 584, 591,
666, 683, 684, 686, 689, 690, 695, 696, 699, 700, 701, 706, 709, 716, 717, 718,
721, 722, 724, 732, 734, 735, 738, 741, 743, 779, 781, 782, 785, 786.
\:\\{cur\_d}, 401, \[402], 405, 442.
\:\\{cur\_edges}, \[330], 331, 332, 333, 334, 335, 336, 344, 345, 346, 347,
348, 349, 350, 351, 352, 403.
\:\\{cur\_exp}, 569, 580, 581, 583, \[666], 667, 668, 669, 670, 673, 679, 687,
691, 692, 695, 700, 706, 709, 711, 716, 717, 719, 724, 728, 730, 732, 733, 741,
742, 744, 748, 753, 754, 755, 757, 759, 760, 764, 765, 766, 771, 772, 773, 774,
775, 776.
\:\\{cur\_ext}, \[602], 607, 619, 620, 625, 627.
\:\\{cur\_file}, \[501], 524, 546, 627, 628.
\:\\{cur\_if}, \[586], 587, 592, 593, 814.
\:\\{cur\_input}, 36, 81, \[498], 499, 505, 516, 517, 624.
\:\\{cur\_length}, \[41], 657.
\:\\{cur\_m}, 401, \[402], 405, 442.
\:\\{cur\_mod}, 82, \[494], 520, 521, 527, 533, 534, 536, 540, 541, 543, 544,
550, 552, 555, 558, 560, 563, 564, 565, 567, 570, 573, 580, 583, 591, 666, 684,
686, 690, 691, 692, 693, 694, 695, 696, 699, 700, 706, 709, 716, 717, 718, 722,
734, 741, 779, 781, 785.
\:\\{cur\_mode}, 540.
\:\\{cur\_n}, 401, \[402], 405, 442.
\:\\{cur\_name}, \[602], 607, 619, 620, 625, 627.
\:\\{cur\_sym}, 82, 198, \[494], 520, 521, 527, 528, 529, 530, 533, 534, 535,
541, 542, 543, 550, 551, 555, 556, 560, 564, 565, 566, 567, 568, 570, 580, 600,
666, 684, 686, 689, 695, 700, 701, 706, 709, 716, 718, 722, 779, 780, 781, 782.
\:\\{cur\_tok}, \[520], 521, 583, 699.
\:\\{cur\_type}, 569, 580, 581, 583, \[666], 667, 668, 669, 670, 673, 679, 686,
687, 691, 692, 695, 700, 706, 709, 711, 715, 716, 717, 722, 724, 728, 730, 731,
732, 733, 742, 744, 748, 753, 754, 755, 757, 759, 760, 762, 764, 765, 766, 771,
772, 773, 774, 775, 776.
\:\\{cur\_wt}, \[330], 344, 345, 346, 348, 349, 350, 351, 352, 403.
\:\\{cur\_x}, 355, 356, \[357], 363, 372, 380, 384, 389, 392, 393, 401, 405,
442, 447.
\:\\{cur\_y}, 355, 356, \[357], 363, 372, 380, 384, 389, 392, 393, 401, 405,
442, 447.
\:\\{curl}, \[264], 265, 267, 268, 269, 273, 277, 288, 290, 291, 296, 730, 747,
748.
\:\9{curl\_}{\&{curl} primitive}, \[199].
\:\\{curl\_command}, \[180], 199, 200, 724.
\:\\{curl\_ratio}, 300, 301, \[302].
\:\\{cycle}, \[180], 199, 200, 735.
\:{cycle spec}, \[360].
\:\.{Cycle spec at line...}, 361.
\:\9{cycle\_}{\&{cycle} primitive}, \[199].
\:\\{cycle\_hit}, 735, 745, 748.
\:\\{c0}, \[482], 483, 484.
\:\\{c1}, \[482], 483.
\:\|{d}, \[358], \[462], \[655], \[658], \[718], \[722], \[734].
\:{data structure assumptions}, 170.
\:\\{data\_lost}, \[353].
\:\\{day}, \[183], 184, 626, 657, 807.
\:\9{day\_}{\&{day} primitive}, \[184].
\:\\{dd}, \[292], 294, 295.
\:{dead cubics}, \[364].
\:\&{debug}, \[7], \[9], \[72], \[78], \[86], \[150], \[172], \[173], \[174], %
\[179], \[817].
\:\.{debug \#}, 817.
\:\\{debug\_help}, 72, 78, 86, \[817].
\:{debugging}, 7, 78, 89, 150, 172, 817.
\:\\{decimal}, \[182], 751.
\:\9{decimal\_}{\&{decimal} primitive}, \[751].
\:\\{decr}, \[16], 42, 44, 62, 65, 80, 82, 83, 84, 85, 98, 117, 119, 142, 157,
185, 195, 212, 297, 319, 325, 332, 333, 335, 336, 345, 346, 347, 351, 352, 394,
395, 423, 432, 450, 456, 485, 491, 492, 505, 517, 519, 524, 552, 583, 659, 664,
665, 708, 718, 722, 734, 799.
\:\9{def\_}{\&{def} primitive}, \[548].
\:\\{def\_ref}, \[575], 576, 585.
\:{defecation}, 650.
\:\\{defined\_macro}, \[180], 235, 237, 569, 570.
\:\\{del}, 368, \[369], 370, 375, 379, 381, 382, 383, 392.
\:\\{delete\_pen\_ref}, 679.
\:\\{delete\_ref}, \[212], 235, 237.
\:\\{delete\_token\_ref}, 519.
\:\\{deletions\_allowed}, \[70], 71, 78, 79, 91, 530, 537, 540.
\:\\{delimiters}, \[180], 199, 200.
\:\9{delimiters\_}{\&{delimiters} primitive}, \[199].
\:\\{delta}, \[99], \[285], 287, 294, 298, 299, 306, \[331], 332, 333, 334, %
\[348], 349, 350, 351, 352, \[462], 464, 465, 466, 467, 468, 469, 470, \[658],
664.
\:\\{delta\_x}, \[285], 287, 298, 299, 305, 306, 307.
\:\\{delta\_y}, \[285], 287, 298, 299, 305, 306, 307.
\:\\{delx}, \[344], 345, 346, \[441], 451, 457.
\:\\{dely}, \[344], 345, 346, \[441], 451, 457.
\:\\{del1}, 368, \[369], 370, 371, 375, 376, 379, 380, 381.
\:\\{del2}, 368, \[369], 370, 371, 373, 375, 376, 377, 379, 380, 381, 382.
\:\\{del3}, 368, \[369], 370, 371, 373, 375, 376, 377, 379, 380, 381, 382.
\:\\{denom}, \[108], \[302], 695.
\:\\{dep\_div}, 775, \[776].
\:\\{dep\_finish}, 770, \[771], 773, 776.
\:\\{dep\_head}, \[168], 239, 240, 251, 257, 259, 667, 669, 715, 766.
\:\\{dep\_list}, 238, \[239], 251, 257, 259, 668, 669, 670, 673, 675, 711, 715,
757, 765, 766, 767, 771, 773, 776.
\:\\{dep\_mult}, 772, \[773], 774.
\:\\{dep\_node\_size}, \[239], 246, 247, 248, 249, 250, 253, 255, 258, 259,
260, 712, 713.
\:\\{dep\_tail}, \[243], 245, 712, 713, 715.
\:\\{dependent}, \[181], 238, 239, 240, 241, 245, 248, 249, 256, 257, 259, 667,
668, 669, 670, 673, 674, 679, 686, 687, 711, 712, 714, 715, 755, 757, 762, 765,
767, 773, 776.
\:\\{depth\_index}, \[633].
\:\\{design\_size}, \[183], 184, 665.
\:\9{design\_size\_}{\&{designsize} primitive}, \[184].
\:\\{diagonal}, \[360], 395, 401, 442, 443, 446, 454, 458.
\:\\{dig}, \[54], 62, 63, 98, 539.
\:\\{digit\_class}, \[188], 189, 208, 210, 535, 538, 539.
\:\9{direction\_}{\&{direction} primitive}, \[751].
\:\\{direction\_of}, \[182], 751.
\:\9{direction\_time\_}{\&{directiontime} primitive}, \[751].
\:\\{direction\_time\_of}, \[182], 751.
\:{dirty \PASCAL}, \[3], 150, 179, 810.
\:\\{discard\_suffixes}, 231.
\:\\{disp\_edges}, \[485].
\:\\{disp\_err}, \[678], 729, 761, 762.
\:\&{div}, \[92].
\:\\{dmax}, \[369], 370, 393.
\:\\{do\_binary}, 693, 695, 696, 718, 721, 722, 734, 735, 750, 751, \[761].
\:\\{do\_nothing}, \[16], 34, 57, 58, 78, 139, 211, 535, 628, 679, 723.
\:\\{do\_nullary}, 693, 750, \[753].
\:\\{do\_statement}, 689, \[778].
\:\\{do\_type\_declaration}, \[785].
\:\\{do\_unary}, 693, 694, 750, \[754].
\:\\{done}, \[15], 47, 53, 120, 121, 245, 251, 266, 267, 275, 290, 306, 307,
316, 321, 339, 340, 344, 345, 348, 349, 350, 351, 352, 364, 390, 394, 415, 418,
426, 437, 441, 445, 453, 485, 486, 493, 505, 550, 552, 575, 579, 583, 591, 616,
620, 621, 627, 683, 699, 713, 716, 736, 767, 781, 782.
\:\\{done1}, \[15], 174, 175, 266, 268, 271, 275, 278, 344, 346, 415, 420, 441,
451, 683, 705, 738, 790.
\:\\{done2}, \[15], 174, 176, 441, 457, 790.
\:\\{done3}, \[15].
\:\\{done4}, \[15].
\:\\{done5}, \[15].
\:\\{done6}, \[15].
\:\.{Doubly free location...}, 176.
\:\\{drawing\_command}, \[180], 199, 200.
\:{dry rot}, 88.
\:\\{ds}, \[643].
\:\\{du}, \[430], \[432], 433.
\:\9{dump\_}{\&{dump}\.{...only by INIMF}}, 814.
\:\\{dump\_four\_ASCII}, \[797].
\:\\{dump\_hh}, \[793], 803.
\:\\{dump\_int}, \[793], 795, 797, 799, 803, 805.
\:\\{dump\_qqqq}, \[793], 797.
\:\\{dump\_wd}, \[793], 799.
\:\\{dup\_offset}, \[414], 423.
\:\\{dv}, \[430], \[432], 433.
\:\\{dx}, \[348], 349, 350, 351, 352, \[415], 418, 419, 429, \[430], 436, 437.
\:\\{dx1}, \[391], 392, 393.
\:\\{dx2}, \[391], 392, 393.
\:\\{dy}, \[415], 418, 419, \[430], 436, 437.
\:\\{dyn\_used}, \[153], 156, 157, 158, 170, 799, 800.
\:\\{dy1}, \[391], 392, 393.
\:\\{dy2}, \[391], 392, 393.
\:\\{d0}, 405, 406, 442, 448, 452, 458.
\:\\{d1}, 405, 406, 442, 452, 458.
\:\|{e}, \[608], \[609], \[620].
\:\\{ec}, 630, 631, 633.
\:\\{edge\_and\_weight}, \[348], 349, 350, 351, 352.
\:\\{edge\_header\_size}, \[329], 337, 353.
\:\\{edge\_prep}, \[331], 345, 346, 349, 350, 351, 352.
\:\9{edges\_}{\&{edges} primitive}, \[783].
\:\\{edges\_type}, \[181], 667, 674, 679, 711, 783, 784.
\:\\{ee}, \[292], 294, 295.
\:\\{effective\_hash\_size}, \[192], 193, 195, 803, 804.
\:\\{eight\_bits}, \[25], 62, 494, 645, 648, 657.
\:\\{eighth\_octant}, \[132], 134, 348, 355, 362, 387, 412, 421.
\:\\{el\_gordo}, \[92], 97, 105, 109, 120, 128, 229.
\:\&{else}, 10.
\:\9{else\_}{\&{else} primitive}, \[588].
\:\\{else\_code}, \[586], 588, 595.
\:\9{else\_if\_}{\&{elseif} primitive}, \[588].
\:\\{else\_if\_code}, \[586], 588, 589.
\:\.{Emergency stop}, 86.
\:\\{empty}, \[16].
\:{empty line at end of file}, 628.
\:\\{empty\_flag}, \[159], 165, 170.
\:\&{end}, 7, 8, 10.
\:\.{End of file on the terminal}, 37, 65.
\:\\{end\_a\_group}, 689, \[690].
\:\\{end\_attr}, \[168], 217, 224, 232.
\:\\{end\_cycle}, \[278], 287, 288, 290, 293.
\:\\{end\_def}, \[548].
\:\9{end\_def\_}{\&{enddef} primitive}, \[548].
\:\\{end\_diagnostic}, \[185], 266, 335, 361, 411, 496, 576, 599, 756, 763.
\:\\{end\_file\_reading}, \[524], 525, 544, 546, 568, 627.
\:\\{end\_for}, \[548].
\:\9{end\_for\_}{\&{endfor} primitive}, \[548].
\:\\{end\_group}, \[180], 199, 200, 689.
\:\9{end\_input\_}{\&{endinput} primitive}, \[571].
\:\\{end\_loop}, \[548].
\:\\{end\_name}, 602, \[607], 616, 621.
\:\\{end\_of\_MF}, \[6], 75, 811.
\:\\{end\_point}, 736, 744.
\:\\{end\_read\_terminal}, \[180], 527, 544, 550, 568.
\:\\{end\_token\_list}, \[519], 521, 541, 585.
\:\&{endcases}, \[10].
\:\9{endgroup\_}{\&{endgroup} primitive}, \[199].
\:\\{endpoint}, \[263], 264, 266, 268, 360, 362, 364, 389, 403, 404, 426, 441,
736, 744, 748.
\:\.{Enormous number...}, 540.
\:\\{ensure\_gf\_open}, \[622], 657.
\:\\{env\_move}, \[443], 446, 449, 450, 451, 452, 454, 455, 457, 458.
\:\\{eoc}, 639, 641, \[642], 643, 645, 658.
\:\\{eof}, 26, 31, 52, 806.
\:\\{eoln}, 31, 52.
\:\\{eq\_type}, \[190], 191, 198, 199, 201, 217, 227, 235, 237, 534, 560, 564,
568, 705, 781.
\:\\{eqtb}, 151, 169, \[190], 191, 198, 200, 201, 233, 235, 237, 495, 502, 818.
\:\\{equal\_to}, \[182], 751.
\:\\{equals}, \[180], 199, 200, 559, 734, 751, 752.
\:\\{equiv}, \[190], 191, 197, 198, 199, 201, 217, 219, 224, 227, 235, 237,
534, 560, 564, 568, 705, 779, 781, 785.
\:\\{err\_help}, 73.
\:\\{error}, 66, 69, 70, 72, 73, \[76], 82, 86, 91, 96, 118, 127, 133, 144,
253, 276, 366, 416, 522, 530, 537, 540, 579, 597, 600, 613, 658, 687, 704, 728,
729, 730, 732, 742, 746, 753, 754, 755, 761, 762, 777, 779, 786.
\:\\{error\_count}, \[70], 71, 76, 80, 778.
\:\\{error\_line}, \[11], 14, 54, 58, 505, 510, 511, 512.
\:\\{error\_message\_issued}, \[70], 76, 88.
\:\\{error\_stop\_mode}, 66, \[67], 68, 76, 86, 91, 678, 806, 814.
\:\\{erstat}, \[27].
\:\.{ETC}, 205.
\:\9{every\_job\_}{\&{everyjob} primitive}, \[199].
\:\\{every\_job\_command}, \[180], 199, 200.
\:\\{exit}, \[15], 16, 37, 47, 76, 113, 160, 205, 221, 227, 231, 241, 252, 316,
325, 358, 432, 533, 594, 595, 614, 683, 718, 734, 758, 761, 765, 779, 791, 814,
817.
\:\\{exp\_err}, \[678], 687, 704, 728, 730, 732, 742, 754, 755, 761, 762, 777.
\:\\{expand}, 595, 600.
\:\\{explicit}, \[264], 268, 271, 272, 277, 288, 305, 307, 360, 368, 743, 746.
\:\.{EXPR}, 210.
\:\9{expr\_}{\&{expr} primitive}, \[561].
\:\\{expr\_arg}, \[180], 683.
\:\\{expr\_base}, \[202], 206, 210, 541, 560, 561, 562, 565, 567, 579, 703.
\:\\{expr\_macro}, \[212], 215, 567, 584.
\:\\{expr\_param}, 541.
\:\\{expression\_binary}, \[180], 751, 752.
\:\\{expression\_tertiary\_macro}, \[180], 734.
\:\\{ext\_bot}, \[636].
\:\\{ext\_delimiter}, \[603], 605, 606, 607.
\:\\{ext\_mid}, \[636].
\:\\{ext\_rep}, \[636].
\:\\{ext\_tag}, \[634].
\:\\{ext\_top}, \[636].
\:\\{exten}, \[634].
\:\\{extensible\_recipe}, 631, \[636].
\:{extensions to \MF}, 2.
\:\.{Extra \\or}, 597.
\:\.{Extra else}, 600.
\:\.{Extra fi}, 600.
\:\\{extra\_space}, 637.
\:\\{extra\_space\_code}, \[637].
\:{eyes and mouth}, 527.
\:\|{f}, \[27], \[28], \[31], \[103], \[105], \[109], \[111], \[245], \[250], %
\[615].
\:\\{factor}, 238.
\:\\{false}, 27, 31, 37, 45, 46, 47, 51, 70, 74, 82, 91, 95, 96, 103, 106, 111,
113, 114, 120, 173, 174, 175, 176, 244, 249, 353, 366, 390, 392, 405, 412, 432,
438, 440, 442, 472, 478, 481, 485, 496, 522, 526, 530, 537, 540, 545, 546, 576,
599, 602, 606, 614, 628, 681, 682, 683, 685, 735, 736, 756, 763, 774, 785, 791.
\:\9{false\_}{\&{false} primitive}, \[671].
\:\\{false\_code}, 667, \[671].
\:\\{fast\_case\_down}, \[348].
\:\\{fast\_case\_up}, \[348].
\:\\{fast\_get\_avail}, \[158], 349, 350, 351, 352.
\:\.{Fatal base file error}, 791.
\:\\{fatal\_error}, 65, \[86], 544, 568, 620, 625.
\:\\{fatal\_error\_stop}, \[70], 71, 76, 86, 625, 811.
\:\\{fet\_symbol}, 567.
\:\\{ff}, \[292], 293, 295, 296, 301, \[302], 307.
\:\9{fi\_}{\&{fi} primitive}, \[588].
\:\\{fi\_code}, \[586], 588, 589, 591, 595, 597, 600.
\:\\{fi\_or\_else}, \[180], 569, 570, 586, 588, 589, 591, 600.
\:\\{fifth\_octant}, \[132], 134, 348, 355, 362, 387, 412, 421.
\:\.{File ended while scanning...}, 530.
\:\\{file\_name\_size}, \[11], 26, 609, 612, 613, 615.
\:\\{file\_offset}, \[54], 55, 57, 58, 61, 336, 627.
\:\\{file\_state}, \[502], 505, 506, 525, 533.
\:\\{fill\_envelope}, \[441].
\:\\{fill\_spec}, \[403], 441, 442, 444.
\:\\{fin\_numeric\_token}, \[533], 535, 538.
\:\\{fin\_offset\_prep}, \[432], 438, 439, 440.
\:\\{final\_cleanup}, 811, \[814].
\:\\{final\_end}, \[6], 526, 811, 816.
\:\\{find\_variable}, \[227], 564, 706, 785.
\:\\{firm\_up\_the\_line}, 532, 546, \[547], 628.
\:\\{first}, \[30], 31, 36, 37, 65, 77, 81, 82, 523, 524, 526, 544, 546, 547,
568, 621, 628.
\:\\{first\_count}, \[54], 510, 511, 512.
\:\\{first\_mem}, \[168], 170, 176, 206.
\:\\{first\_octant}, \[132], 134, 348, 355, 362, 364, 367, 368, 371, 373, 386,
387, 412, 419, 421, 428.
\:\\{first\_text\_char}, \[19], 24.
\:\\{fix\_date\_and\_time}, 816.
\:\\{fix\_dependencies}, \[251], 252, 767.
\:\\{fix\_fragment}, 736, \[737], 744.
\:\\{fix\_needed}, \[243], 244, 246, 247, 248, 249, 251, 252, 767.
\:\\{fix\_word}, \[631], 632, 637, 643.
\:\\{FIXTHIS}, 531, 598, 680, 801, 802.
\:\\{flush\_below\_variable}, 231, \[232].
\:\\{flush\_char}, \[42].
\:\\{flush\_cur\_exp}, \[679], 687, 704, 728, 730, 732, 742, 760.
\:\\{flush\_list}, \[171], 353, 519, 564, 585, 785.
\:\\{flush\_node\_list}, \[171], 550, 679, 706.
\:\\{flush\_string}, \[44], 198, 807.
\:\\{flush\_symbol}, \[232], 235, 237, 558.
\:\\{flush\_token\_list}, \[204], 212, 221.
\:\\{flush\_variable}, \[231], 564, 785.
\:{font metric files}, 629.
\:\9{for\_}{\&{for} primitive}, \[548].
\:\\{for\_loop}, \[502], 508.
\:\9{for\_suffixes\_}{\&{forsuffixes} primitive}, \[548].
\:\\{for\_suffixes\_loop}, \[502], 508.
\:\.{Forbidden token found...}, 530.
\:\\{force\_eof}, 526, \[545], 546, 573.
\:\\{forty\_five\_deg}, \[102], 138.
\:\\{forward}, 72, 532, 569.
\:\\{found}, \[15], 160, 163, 164, 194, 195, 221, 222, 275, 290, 297, 298, 301,
415, 485, 490, 533, 535, 550, 551, 575, 580, 614, 683, 699, 709, 710.
\:\\{found1}, \[15], 790.
\:\\{found2}, \[15], 790.
\:\\{four\_quarters}, \[149], 790, 791.
\:\\{fourth\_octant}, \[132], 134, 348, 355, 360, 362, 387, 410, 412, 421.
\:\\{frac\_mult}, 695, \[774].
\:\\{fraction}, \[101], 103, 105, 108, 111, 120, 137, 138, 141, 142, 143, 239,
242, 243, 245, 248, 255, 286, 289, 292, 302, 304, 305, 358, 369, 372, 399, 428,
432, 767, 773, 774, 776.
\:\\{fraction\_four}, \[101], 108, 117, 119, 121, 125, 126, 302.
\:\\{fraction\_half}, \[101], 145, 294, 370, 759.
\:\\{fraction\_one}, \[101], 103, 104, 105, 135, 138, 141, 142, 143, 241, 243,
248, 291, 294, 296, 297, 301, 358, 359, 364, 368, 373, 375, 377, 379, 382, 393,
400, 431, 432, 434, 438, 660, 661, 712, 767.
\:\\{fraction\_three}, \[101], 108, 294, 302.
\:\\{fraction\_threshold}, \[245].
\:\\{fraction\_two}, \[101], 108, 117, 120, 135.
\:\\{fragment}, \[265], 266, 667, 726, 736, 744.
\:\\{free}, \[172], 174, 175, 176, 177, 178.
\:\\{free\_avail}, \[157], 171, 204, 237, 251, 342, 706, 716.
\:\\{free\_node}, \[165], 171, 204, 231, 232, 237, 246, 248, 249, 250, 253,
255, 258, 259, 260, 274, 275, 353, 385, 424, 469, 471, 519, 593, 670, 679, 695,
726, 728, 731, 733, 743, 747, 761, 771, 772.
\:\9{from\_}{\&{from} primitive}, \[199].
\:\\{from\_token}, \[180], 199, 200.
\:\\{frozen\_colon}, \[192], 600.
\:\\{frozen\_end\_def}, \[192], 530.
\:\\{frozen\_end\_group}, \[192], 689.
\:\\{frozen\_end\_loop}, \[192], 557.
\:\\{frozen\_fi}, \[192], 528.
\:\\{frozen\_inaccessible}, \[192], 780.
\:\\{frozen\_left\_bracket}, \[192], 701.
\:\\{frozen\_relax}, \[192], 529.
\:\\{frozen\_slash}, \[192], 695.
\:\\{frozen\_undefined}, \[192], 235.
\:{Fuchs, David Raymond}, 2, 644.
\:\\{future\_pen}, \[181], 667, 679, 711, 722, 723.
\:\\{future\_pen\_type}, 674.
\:\|{g}, \[47].
\:\\{gamma}, \[302], \[462], 463, 464.
\:\\{general\_macro}, \[212], 215, 563, 579.
\:\\{generic\_subscript}, \[217], 224, 229, 231, 705, 782.
\:\\{get}, 26, 29, 31, 33, 628, 794.
\:\\{get\_avail}, \[156], 158, 221, 222, 233, 251, 338, 343, 345, 346, 520,
529, 530, 550, 560, 563, 566, 568, 581, 584, 699, 707, 708, 709, 716, 720, 781.
\:\\{get\_clear\_symbol}, \[558], 560, 564, 568.
\:\\{get\_expression}, 700, 721.
\:\\{get\_next}, 70, 72, 82, 494, 527, 528, 532, \[533], 541, 544, 550, 555,
560, 564, 565, 566, 567, 569, 575, 583, 591, 616, 780, 781, 782, 786.
\:\\{get\_node}, \[160], 166, 203, 219, 220, 224, 225, 226, 229, 230, 235, 236,
247, 262, 329, 332, 333, 337, 372, 389, 414, 415, 420, 463, 470, 471, 520, 550,
560, 566, 567, 592, 668, 687, 712, 713, 715, 726, 733, 737.
\:\\{get\_strings\_started}, \[47], 51, 811.
\:\\{get\_symbol}, 557, 558, 560, 566, 567, \[780], 781.
\:\\{get\_x\_next}, \[569], 580, 582, 584, 668, 683, 684, 685, 686, 687, 694,
695, 696, 699, 700, 705, 706, 709, 716, 717, 718, 721, 722, 724, 730, 732, 734,
735, 738, 741, 743, 778.
\:\\{gf\_buf}, 647, \[648], 650, 651.
\:\\{gf\_buf\_size}, \[11], 14, 647, 648, 649, 651, 652, 665.
\:\\{gf\_file}, \[622], 645, 647, 650, 665.
\:\\{gf\_four}, \[653], 655, 658, 659, 663, 665.
\:\\{gf\_id\_byte}, \[641], 657, 665.
\:\\{gf\_index}, \[647], 648, 650.
\:\\{gf\_limit}, 647, \[648], 649, 651, 652.
\:\\{gf\_max\_x}, \[645], 657, 665.
\:\\{gf\_max\_y}, \[645], 657, 665.
\:\\{gf\_min\_x}, \[645], 657, 665.
\:\\{gf\_min\_y}, \[645], 657, 665.
\:\\{gf\_new\_row}, \[655], 663, 664.
\:\\{gf\_offset}, 647, \[648], 649, 651, 658, 665.
\:\\{gf\_out}, \[651], 653, 654, 655, 656, 657, 658, 664, 665.
\:\\{gf\_paint}, \[655], 661, 662.
\:\\{gf\_prev\_ptr}, \[645], 646, 657, 658, 665.
\:\\{gf\_ptr}, 647, \[648], 649, 651, 652, 657, 658, 665.
\:\\{gf\_string}, \[656], 657.
\:\\{gf\_swap}, \[651].
\:\\{gf\_three}, \[654].
\:\\{gf\_two}, \[654], 655, 664.
\:\\{gf\_x\_max}, 660.
\:\\{gf\_x\_min}, 663.
\:\\{gf\_y\_max}, 663.
\:\\{gf\_y\_min}, 659.
\:\\{give\_err\_help}, 84.
\:\\{given}, \[264], 265, 268, 269, 273, 279, 288, 290, 291, 731, 733, 737.
\:\\{given\_list}, 736, 737, 748.
\:\&{goto}, \[75].
\:\\{greater\_or\_equal}, \[182], 751.
\:\\{greater\_than}, \[182], 751.
\:\\{group\_line}, \[688], 689.
\:\&{gubed}, \[7].
\:{Guibas, Leonidas Ioannis}, 2, 407.
\:\|{h}, \[194], \[266], \[275], \[329], \[335], \[337], \[339], \[341], %
\[353], \[361], \[364], \[403], \[411], \[415], \[426], \[441], \[462], \[485],
\[658], \[716], \[781].
\:\\{half}, \[93], 98, 107, 110, 117, 126, 135, 143, 220, 247, 318, 321, 325,
359, 400, 401.
\:\\{half\_buf}, 647, \[648], 649, 651, 652.
\:\\{half\_error\_line}, \[11], 14, 505, 510, 511, 512.
\:\\{half\_fraction\_threshold}, \[245], 248, 249, 255, 260.
\:\\{half\_scaled\_threshold}, \[245], 248, 249.
\:\\{half\_unit}, \[97], 115, 344, 364, 400, 401, 405, 442, 447, 448, 452, 458,
463, 464, 466.
\:\\{halfword}, 146, \[149], 151, 165, 198, 231, 331, 339, 349, 350, 351, 352,
426, 432, 494, 495, 497, 718, 722, 734.
\:\\{hash}, \[190], 191, 192, 194, 195, 495, 527, 803, 804.
\:\\{hash\_base}, 803, 804.
\:\\{hash\_is\_full}, \[190], 195.
\:\\{hash\_prime}, \[12], 14, 194, 196, 795, 796.
\:\\{hash\_size}, \[12], 14, 190, 191, 192, 196, 197, 202, 217, 233, 236, 237,
795, 796, 813.
\:\\{hash\_used}, \[190], 193, 195, 803, 804.
\:\\{header}, 632.
\:{Hedrick, Charles Locke}, 3.
\:\\{height\_index}, \[633].
\:\\{help\_line}, \[73], 83, 84, 528, 786.
\:\\{help\_ptr}, \[73], 74, 83, 84.
\:\\{help0}, \[73].
\:\\{help1}, \[73], 86, 88, 565, 584, 597, 600, 696, 730, 738, 742, 792.
\:\\{help2}, 66, \[73], 82, 83, 87, 88, 118, 127, 133, 144, 253, 276, 540, 658,
689, 732, 753, 754, 761, 777, 779.
\:\\{help3}, 66, \[73], 91, 416, 528, 537, 579, 580, 704, 717, 721, 724, 728,
729, 732, 746, 755, 762, 779, 780.
\:\\{help4}, \[73], 83, 96, 366, 530, 684, 687.
\:\\{help5}, \[73], 559, 706, 786.
\:\\{help6}, \[73].
\:\.{Here is how much...}, 813.
\:\9{hex\_}{\&{hex} primitive}, \[751].
\:\\{hex\_op}, \[182], 751.
\:\\{hh}, 146, \[149], 150, 154, 216, 233, 263, \[337], \[415], 417, 418, 793,
794.
\:\\{hi}, \[148].
\:\\{hi\_mem\_base}, \[12], 14, 152, 154, 156, 160, 168, 170, 171, 172, 176,
177, 204, 206, 227, 541, 705, 795, 796, 799, 800, 813.
\:\\{history}, \[70], 71, 76, 86, 88, 185, 625, 811, 814.
\:\\{hlp1}, \[73].
\:\\{hlp2}, \[73].
\:\\{hlp3}, \[73].
\:\\{hlp4}, \[73].
\:\\{hlp5}, \[73].
\:\\{hlp6}, \[73].
\:\\{ho}, \[148], 327, 336, 342, 490, 660.
\:{Hobby, John Douglas}, 280, 459.
\:\|{i}, \[143], \[510].
\:\.{I can't find file x}, 620.
\:\.{I can't find PLAIN...}, 614.
\:\.{I can't go on...}, 88.
\:\.{I can't read MF.POOL}, 51.
\:\.{I can't write on file x}, 620, 625.
\:\\{id\_lookup}, \[194], 198, 535.
\:\\{identity}, \[502], 508, 702.
\:\\{identity\_macro}, \[168], 502, 702, 703.
\:\9{if\_}{\&{if} primitive}, \[199].
\:\\{if\_code}, \[586], 592, 600.
\:\\{if\_limit}, \[586], 587, 592, 593, 594, 595, 600.
\:\\{if\_line}, \[586], 587, 592, 593, 814.
\:\\{if\_line\_field}, \[586], 592, 593, 814.
\:\\{if\_node\_size}, \[586], 592, 593.
\:\\{if\_test}, \[180], 199, 200, 569, 570, 591, 595, 814.
\:\.{IMPOSSIBLE}, 206.
\:\\{in\_open}, \[501], 523, 524, 526.
\:\\{in\_state\_record}, \[497], 498.
\:\\{incoming}, \[401].
\:\.{Incomplete if...}, 528.
\:\.{Incomplete string constant...}, 537.
\:\\{incr}, \[16], 31, 37, 42, 43, 45, 46, 53, 58, 59, 63, 65, 76, 84, 91, 104,
112, 119, 129, 136, 140, 156, 158, 177, 195, 212, 287, 290, 303, 318, 319, 321,
323, 324, 325, 336, 347, 349, 350, 351, 352, 366, 394, 395, 401, 420, 423, 432,
437, 449, 450, 451, 455, 456, 457, 476, 482, 485, 491, 492, 493, 516, 523, 535,
536, 538, 539, 546, 552, 566, 576, 578, 581, 583, 584, 585, 607, 609, 614, 616,
621, 651, 658, 702, 711, 803, 816.
\:\\{independent}, \[181], 220, 238, 241, 243, 251, 667, 711, 712, 714, 715.
\:\\{independent\_being\_fixed}, \[251].
\:\\{independent\_needing\_fix}, \[243], 246, 247, 248, 249.
\:\\{index}, 497, \[499], 500, 501, 502, 523, 524, 526.
\:\\{index\_field}, \[497], 499.
\:\\{info}, \[154], 159, 170, 179, 202, 203, 206, 207, 209, 212, 215, 216, 217,
221, 222, 227, 230, 231, 233, 235, 236, 237, 239, 241, 242, 245, 246, 247, 248,
249, 250, 251, 252, 254, 255, 257, 259, 260, 327, 328, 329, 331, 334, 338, 339,
340, 342, 343, 345, 346, 348, 349, 350, 351, 352, 410, 411, 413, 420, 426, 445,
454, 488, 490, 520, 529, 530, 541, 543, 550, 551, 557, 560, 563, 564, 566, 567,
574, 576, 577, 579, 580, 581, 582, 584, 585, 660, 669, 670, 676, 703, 705, 707,
708, 709, 712, 713, 716, 720, 758, 766, 768, 769, 771, 781, 785, 818.
\:\.{INIMF}, 8, 11, 12, 47, 50, 787, 810.
\:\&{init}, \[8], \[47], \[50], \[166], \[198], \[790], \[811], \[814], \[815].
\:\\{init\_big\_node}, \[220], 687, 715, 733.
\:\\{init\_gf}, \[657].
\:\\{init\_pool\_ptr}, \[39], 42, 811, 813.
\:\\{init\_prim}, 811, \[815].
\:\\{init\_randoms}, \[143].
\:\\{init\_screen}, \[472], 475, 476, 477, 478, 479.
\:\\{init\_str\_ptr}, \[39], 43, 607, 811, 813.
\:\\{init\_terminal}, \[37], 526.
\:\\{initialize}, \[4], 811, 816.
\:{inner loop}, 158, 650.
\:\\{input}, \[180], 569, 570, 571, 572.
\:\9{input\_}{\&{input} primitive}, \[571].
\:\\{input\_file}, \[501].
\:\\{input\_ln}, 30, \[31], 37, 58, 65, 546, 628.
\:\\{input\_ptr}, \[498], 505, 506, 516, 517, 525, 526, 544, 624.
\:\\{input\_stack}, 78, \[498], 505, 516, 517, 624.
\:\\{ins\_err}, 706.
\:\\{ins\_error}, \[522], 528, 684, 780.
\:\\{ins\_list}, \[518], 530.
\:\.{insert>}, 81.
\:\\{inserted}, \[502], 508, 518, 519, 522.
\:\\{int}, 146, \[149], 150, 202, 329, 586, 793, 794, 796.
\:\\{inteer}, 430.
\:\\{integer}, 13, 45, 47, 54, 59, 63, 64, 76, 87, 89, 97, 98, 101, 102, 103,
105, 108, 109, 111, 113, 115, 117, 120, 122, 125, 128, 132, 138, 145, 146, 149,
153, 160, 169, 179, 183, 190, 194, 205, 227, 241, 245, 248, 249, 250, 305, 312,
314, 316, 325, 330, 331, 335, 336, 341, 344, 348, 358, 364, 365, 391, 402, 403,
411, 415, 430, 432, 441, 443, 444, 462, 480, 482, 485, 488, 501, 503, 510, 550,
575, 586, 590, 591, 595, 608, 609, 613, 624, 645, 648, 653, 654, 655, 657, 658,
666, 688, 765, 773, 790, 791, 810, 812, 817.
\:\\{interaction}, 65, 66, \[67], 68, 69, 76, 78, 80, 84, 85, 86, 91, 544, 547,
568, 620, 625, 678, 805, 806, 807, 814.
\:\9{interim\_}{\&{interim} primitive}, \[199].
\:\\{interim\_command}, \[180], 199, 200.
\:\\{internal}, \[183], 185, 236, 237, 252, 258, 275, 364, 415, 547, 570, 575,
626, 657, 658, 665, 683, 690, 709, 753, 754, 761, 818.
\:\\{internal\_quantity}, \[180], 184.
\:\\{interrupt}, \[89], 90, 91, 685.
\:\.{Interruption}, 91.
\:\\{intersect}, \[182], 751.
\:\9{intersect\_}{\&{intersect} primitive}, \[751].
\:\\{invalid\_code}, \[22], 24.
\:\\{is\_empty}, \[159], 162, 176, 177.
\:\\{isolated\_classes}, \[188], 211, 535.
\:{italic correction}, \[633].
\:\\{italic\_index}, \[633].
\:\\{iteration}, \[180], 548, 549, 550.
\:\\{its\_all\_over}, 814.
\:\|{j}, \[45], \[46], \[59], \[143], \[194], \[198], \[510], \[609], \[613], %
\[614], \[790], \[791].
\:\\{j\_random}, \[141], 142, 144, 145.
\:{Japanese characters}, 630.
\:{Jensen, Kathleen}, 10.
\:\\{jj}, \[143].
\:\.{job aborted}, 544.
\:\.{job aborted, file error...}, 620.
\:\\{job\_name}, 85, \[617], 618, 619, 622, 624, 625, 627, 807, 812, 813, 814.
\:\9{job\_name\_}{\&{jobname} primitive}, \[751].
\:\\{job\_name\_op}, \[182], 751.
\:\\{jump\_out}, \[75], 76, 78, 86, 625.
\:\|{k}, \[45], \[46], \[47], \[62], \[63], \[65], \[98], \[117], \[123], %
\[125], \[128], \[132], \[138], \[142], \[143], \[169], \[194], \[198], \[286],
\[305], \[325], \[339], \[348], \[364], \[411], \[415], \[424], \[426], \[432],
\[444], \[476], \[482], \[485], \[533], \[547], \[563], \[609], \[613], \[615],
\[620], \[624], \[650], \[656], \[657], \[790], \[791], \[812], \[817].
\:\\{kern}, \[635].
\:\\{kern\_flag}, \[635].
\:\\{knil}, \[328], 329, 332, 333, 335, 337, 346, 347, 350, 410, 411, 413, 414,
422, 423, 432, 438, 440, 442, 446, 450, 454, 456, 659.
\:\\{knot\_node\_size}, 726, 733, 747.
\:\\{knot\_size}, \[263], 274, 372, 385, 389, 463, 469, 470, 471.
\:\\{knots}, \[275], 277, 278.
\:\\{known}, \[181], 238, 245, 258, 259, 580, 667, 668, 674, 675, 679, 695,
700, 711, 714, 715, 717, 727, 729, 730, 732, 733, 742, 753, 755, 757, 759, 760,
765, 766, 767, 771, 772, 774, 775.
\:\\{known\_pair}, 726, 727, \[728], 731, 743.
\:{Knuth, Donald Ervin}, 2, 80.
\:\|{l}, \[47], \[145], \[194], \[198], \[205], \[316], \[510], \[591], \[594],
\[624], \[781], \[790], \[817].
\:\\{l\_delim}, 565, \[575], 580, \[683], 686, 687, \[779].
\:\\{label\_factor}, \[183], 184.
\:\9{label\_factor\_}{\&{labelfactor} primitive}, \[184].
\:\\{labeling}, \[183], 184.
\:\9{labeling\_}{\&{labeling} primitive}, \[184].
\:\\{labeling\_command}, \[180].
\:\\{lambda}, \[399], 400.
\:\\{lambda\_denom}, \[399], 400.
\:\\{lambda\_num}, \[399], 400.
\:{Lane, Jeffrey Michael}, 308.
\:\\{last}, \[30], 31, 36, 37, 65, 77, 81, 82, 526, 544, 547, 568, 614, 621.
\:\\{last\_nonblank}, \[31].
\:\\{last\_text\_char}, \[19], 24.
\:\\{last\_window}, \[329], 337, 485.
\:\\{last\_window\_time}, \[329], 337, 485.
\:\\{left\_brace}, \[180], 199, 200, 722.
\:\\{left\_bracket}, \[180], 199, 200, 699, 701, 716, 718, 781, 782.
\:\\{left\_bracket\_class}, \[188], 189, 208, 209.
\:\\{left\_col}, \[475], \[480], 482, 485, 489.
\:\\{left\_curl}, \[264], 269, 273, 277, 288, 301, 737, 747.
\:\\{left\_delim}, 580.
\:\\{left\_delimiter}, \[180], 563, 565, 583, 683, 779.
\:\\{left\_delta}, \[168], 288.
\:\\{left\_given}, \[264], 269, 273, 288, 298, 306, 737.
\:\\{left\_length}, 463, 465, 467, 468, 469, 470.
\:\\{left\_octant}, \[360], 362, 364, 389, 394, 395, 403, 441.
\:\\{left\_row}, 475.
\:\\{left\_tension}, \[264], 268, 270, 294, 295, 300, 301, 305, 307, 746.
\:\\{left\_transition}, \[360], 395, 405, 442, 446, 454.
\:\\{left\_type}, \[263], 264, 265, 266, 268, 269, 271, 272, 273, 275, 277,
278, 279, 287, 288, 290, 291, 293, 305, 307, 360, 363, 364, 366, 372, 389, 403,
441, 463, 726, 736, 737, 744, 746, 747, 748.
\:\\{left\_v}, 463, 465, 467, 468, 469, 470.
\:\\{left\_x}, \[263], 264, 271, 277, 288, 305, 307, 360, 363, 366, 368, 371,
372, 373, 374, 380, 381, 382, 383, 384, 389, 393, 399, 406, 427, 431, 445, 453,
463, 746.
\:\\{left\_y}, \[263], 264, 271, 277, 288, 307, 360, 363, 366, 372, 375, 376,
377, 378, 380, 381, 382, 383, 384, 389, 393, 399, 406, 427, 431, 445, 453, 463,
746.
\:\\{left\_z\_1}, \[641].
\:\\{left\_z\_82}, \[641].
\:\\{length}, \[40], 46, 194, 627.
\:\9{length\_}{\&{length} primitive}, \[751].
\:\\{length\_op}, \[182], 751.
\:\\{less\_or\_equal}, \[182], 751.
\:\\{less\_than}, \[182], 751.
\:\9{let\_}{\&{let} primitive}, \[199].
\:\\{let\_command}, \[180], 199, 200.
\:\\{letter\_class}, \[188], 189, 206, 211.
\:\\{lf}, 630.
\:\\{lh}, 146, \[149], 150, 154, 190, 630, 631.
\:\\{lhs}, \[252].
\:\\{lig\_kern}, 634, 635.
\:\\{lig\_kern\_command}, 631, \[635].
\:\\{lig\_tag}, \[634].
\:\\{limit}, 497, \[499], 500, 502, 513, 523, 525, 526, 535, 536, 544, 546,
547, 568, 616, 627, 628, 816.
\:\\{limit\_field}, 81, \[497], 499, 624.
\:\\{line}, 78, 187, \[501], 507, 523, 524, 526, 546, 591, 592, 628, 689.
\:\\{line\_edges}, \[344], 348, 443, 447.
\:\\{line\_stack}, \[501], 523, 524.
\:\\{link}, \[154], 156, 157, 158, 159, 160, 165, 170, 171, 175, 179, 204, 205,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 229, 230, 231,
232, 233, 235, 236, 237, 239, 241, 242, 245, 246, 247, 248, 249, 250, 251, 254,
255, 257, 258, 259, 260, 263, 266, 274, 275, 277, 278, 279, 287, 290, 303, 327,
328, 329, 331, 332, 333, 334, 335, 337, 338, 339, 340, 341, 342, 343, 345, 346,
347, 349, 350, 351, 352, 353, 361, 364, 366, 367, 372, 373, 374, 375, 377, 378,
379, 382, 383, 384, 385, 388, 389, 390, 394, 395, 399, 403, 404, 406, 410, 411,
413, 414, 415, 418, 420, 422, 423, 424, 426, 427, 428, 432, 434, 437, 438, 439,
441, 442, 445, 446, 450, 452, 453, 454, 456, 458, 463, 465, 469, 470, 471, 485,
490, 509, 514, 519, 541, 550, 551, 560, 563, 564, 566, 567, 568, 574, 575, 576,
577, 578, 579, 581, 583, 584, 585, 586, 592, 593, 594, 660, 668, 669, 670, 676,
699, 705, 706, 707, 708, 712, 713, 715, 716, 720, 736, 737, 744, 746, 747, 748,
758, 766, 768, 769, 781, 785, 799, 814, 818.
\:\\{list\_tag}, \[634].
\:\\{llink}, \[159], 161, 162, 165, 166, 170, 176.
\:\\{load\_base\_file}, \[791], 816.
\:\\{loc}, \[36], 37, 81, 497, \[499], 500, 502, 506, 508, 513, 514, 518, 521,
523, 525, 526, 535, 536, 538, 539, 541, 543, 544, 546, 568, 585, 614, 616, 627,
628, 816.
\:\\{loc\_field}, 36, \[497], 499.
\:\\{log}, 816.
\:\\{log\_file}, \[54], 56, 69, 624, 812.
\:\\{log\_name}, \[622], 624, 812.
\:\\{log\_only}, \[54], 57, 58, 61, 69, 91, 544, 624, 807.
\:\&{loop}, 15, \[16].
\:\9{loop\_}{\&{loop} primitive}, \[548].
\:\\{loop\_defining}, 556.
\:\\{loop\_repeat}, \[180], 548, 549, 550, 556.
\:\\{loop\_text}, \[502].
\:\|{m}, \[47], \[63], \[316], \[336], \[341], \[411], \[444], \[488], \[510], %
\[560], \[563], \[568], \[595], \[624], \[658], \[817].
\:\\{m\_adjustment}, \[488], 489, 490.
\:\\{m\_atan}, 287.
\:\\{m\_exp}, \[128], 759.
\:\9{m\_exp\_}{\&{mexp} primitive}, \[751].
\:\\{m\_exp\_op}, \[182], 751, 759.
\:\\{m\_log}, \[125], 127, 145, 759.
\:\9{m\_log\_}{\&{mlog} primitive}, \[751].
\:\\{m\_log\_op}, \[182], 751, 759.
\:\\{m\_max}, \[329], 331, 337.
\:\\{m\_min}, \[329], 331, 337.
\:\\{m\_offset}, \[329], 331, 334, 336, 337, 341, 345, 346, 349, 350, 351, 352,
489, 660, 663.
\:\\{m\_window}, \[480], 484, 489.
\:\\{mac\_name}, \[718], \[722], \[734].
\:\\{macro}, \[502], 508, 514, 518, 564, 568, 585.
\:\\{macro\_at}, \[553], 554.
\:\\{macro\_call}, 570, 574, \[575], 707, 708, 720.
\:\\{macro\_def}, \[180], 548, 549, 550, 560, 563.
\:\\{macro\_name}, \[575], 576, 579, 580, 584, 585.
\:\\{macro\_prefix}, \[553], 554.
\:\\{macro\_ref}, \[698], 699, 708.
\:\\{macro\_special}, 550, 553, 554, 564.
\:\\{macro\_suffix}, \[553], 564.
\:\\{main\_control}, 811, 816.
\:\\{major\_axis}, \[462], 464, 466.
\:\\{make\_choices}, \[275], 280, 283, 284, 748.
\:\\{make\_ellipse}, \[462], 463.
\:\\{make\_exp\_copy}, 710, \[711], 721.
\:\\{make\_fraction}, \[103], 105, 108, 111, 121, 138, 145, 255, 287, 294, 295,
296, 297, 298, 299, 300, 301, 302, 306, 307, 345, 346, 392, 400, 433, 451, 457,
464, 466.
\:\\{make\_good}, 401, 402, 405, 442.
\:\\{make\_moves}, 314, \[316], 325, 406, 445, 449, 453.
\:\\{make\_name\_string}, \[615].
\:\\{make\_op\_def}, \[560].
\:\\{make\_pen}, \[415].
\:\9{make\_pen\_}{\&{makepen} primitive}, \[751].
\:\\{make\_pen\_op}, \[182], 751.
\:\\{make\_scaled}, \[111], 249, 695, 775.
\:\\{make\_spec}, \[364], 365, 371, 386, 428.
\:\\{make\_string}, \[43], 48, 52, 195, 536, 607, 615, 807, 812.
\:\\{materialize\_pen}, 722, \[723].
\:\\{max\_allowed}, \[364], 366.
\:\\{max\_buf\_stack}, \[30], 31, 526, 813.
\:\\{max\_class}, \[188].
\:\\{max\_coef}, \[242], \[430], 431, 767, 773, 776.
\:\\{max\_expression\_command}, \[180], 734.
\:\\{max\_halfword}, 11, 12, 14, \[146], 147, 149, 159, 160, 166, 167, 202, 327.
\:\\{max\_in\_open}, \[11], 501, 502, 523.
\:\\{max\_in\_stack}, \[498], 516, 526, 813.
\:\\{max\_internal}, \[183].
\:\\{max\_nest\_stack}, 813.
\:\\{max\_offset}, \[410].
\:\\{max\_param\_stack}, \[503], 526, 585, 702, 813.
\:\\{max\_primary\_command}, \[180], 683, 695, 718, 722, 734.
\:\\{max\_print\_line}, \[11], 14, 54, 58, 60, 66, 336, 627.
\:\\{max\_quarterword}, \[146], 147, 149.
\:\\{max\_secondary\_command}, \[180], 718.
\:\\{max\_selector}, \[54], 186, 505, 624.
\:\\{max\_special\_class}, \[188].
\:\\{max\_statement\_command}, \[180].
\:\\{max\_strings}, \[11], 38, 43, 147, 607, 798, 813.
\:\\{max\_tertiary\_command}, \[180], 722.
\:\\{max\_var\_used}, \[153], 160, 170, 800, 813.
\:\\{maxx}, \[643].
\:\\{maxy}, \[643].
\:{Meggitt, John E.}, 136.
\:\\{mem}, 11, 12, 151, \[152], 154, 159, 166, 168, 169, 170, 172, 174, 179,
202, 204, 216, 217, 226, 229, 233, 239, 245, 263, 329, 337, 410, 413, 586, 799,
800, 818.
\:\\{mem\_base}, \[12], 14, 147, 151, 152, 160, 168, 170, 172, 173, 174, 177,
178, 179, 799, 800, 813.
\:\\{mem\_end}, \[154], 156, 170, 172, 174, 175, 178, 179, 206, 799, 800, 813.
\:\\{mem\_max}, \[11], 12, 14, 146, 147, 152, 156, 168, 172, 800, 813.
\:\\{memory\_word}, 146, \[149], 150, 152, 227, 793.
\:\\{message\_command}, \[180].
\:\.{METAFONT capacity exceeded ...}, 87.
\:\9{METAFONT capacity exceeded buffer size}{\quad buffer size}, 31, 523.
\:\9{METAFONT capacity exceeded hash size}{\quad hash size}, 195.
\:\9{METAFONT capacity exceeded input stack size}{\quad input stack size}, 516.
\:\9{METAFONT capacity exceeded macro/}{\quad macro/pixel memory size}, 156.
\:\9{METAFONT capacity exceeded move table size}{\quad move table size}, 406,
446, 454.
\:\9{METAFONT capacity exceeded number of strings}{\quad number of strings},
43, 607.
\:\9{METAFONT capacity exceeded parameter stack size}{\quad parameter stack
size}, 566, 585, 702.
\:\9{METAFONT capacity exceeded path size}{\quad path size}, 287.
\:\9{METAFONT capacity exceeded point/}{\quad point/path memory size}, 160.
\:\9{METAFONT capacity exceeded pool size}{\quad pool size}, 42.
\:\9{METAFONT capacity exceeded text input levels}{\quad text input levels},
523.
\:\9{METAFONTbook}{\tenss The \MF book}, 1, 189, 684, 810.
\:\9{METAFONT84}{\MF84}, \[1].
\:\\{MF}, \[4].
\:\.{MF.POOL check sum...}, 53.
\:\.{MF.POOL doesn't match}, 53.
\:\.{MF.POOL has no check sum}, 52.
\:\.{MF.POOL line doesn't...}, 52.
\:\\{MF\_area}, \[604], 627.
\:\\{MF\_base\_default}, \[610], 611, 613.
\:\.{MFinputs}, 604.
\:\\{mid}, \[636].
\:\\{mid\_line}, 81, 523.
\:\\{min\_col}, \[488], 489, 490.
\:\\{min\_command}, \[180], 569.
\:\\{min\_expression\_command}, \[180], 734, 735.
\:\\{min\_halfword}, 12, \[146], 147, 148, 149, 327, 329, 343, 345, 346, 488,
800.
\:\\{min\_primary\_command}, \[180], 683, 695, 718, 722, 734.
\:\\{min\_quarterword}, \[146], 147, 149, 635.
\:\\{min\_secondary\_command}, \[180], 718.
\:\\{min\_tension}, 742.
\:\\{min\_tertiary\_command}, \[180], 722.
\:\\{minor\_axis}, \[462], 464, 466.
\:\\{minus}, \[182], 721, 751, 754, 757, 761, 765.
\:\\{minx}, \[643].
\:\\{miny}, \[643].
\:\\{ml}, \[331].
\:\\{mm}, 663.
\:\\{mm0}, \[444], 446, 452, 454, 458.
\:\\{mm1}, \[444], 446, 454.
\:\&{mod}, \[495], \[496].
\:\\{mode\_command}, \[180].
\:{Moler, Cleve}, 120.
\:\\{month}, \[183], 184, 626, 657, 807.
\:\9{month\_}{\&{month} primitive}, \[184].
\:\\{months}, \[624], 626.
\:\\{more\_name}, 602, \[606], 616, 621.
\:{Morrison, Donald Ross}, 120.
\:\\{move}, \[312], 313, 316, 319, 320, 323, 324, 325, 348, 349, 350, 396, 406,
443, 445, 449, 452, 453, 455, 458.
\:\\{move\_increment}, \[314], 315, 317, 318.
\:\\{move\_ptr}, \[312], 319, 320, 323, 324, 325, 406, 444, 445, 446, 449, 450,
451, 452, 453, 454, 455, 456, 457, 458.
\:\\{move\_size}, \[11], 312, 325, 348, 406, 443, 446, 454.
\:\\{move\_to\_edges}, \[348], 403, 452, 458.
\:\\{moves}, 348, 351, 352.
\:\\{mr}, \[331].
\:\&{mtype}, \[4].
\:\\{mu}, \[399], 400.
\:\\{mu\_denom}, \[399], 400.
\:\\{mu\_num}, \[399], 400.
\:\.{Must increase the x}, 791.
\:\\{m0}, \[344], 345, 346, \[348], 349, 350, 351, 352, \[403], 405, \[441],
442, 448, 452, 458.
\:\\{m1}, \[344], 345, 346, \[348], 349, 350, 351, 352, \[403], 405, \[441],
442, 452, 458.
\:\|{n}, \[47], \[63], \[64], \[87], \[103], \[105], \[109], \[111], \[227], %
\[231], \[286], \[316], \[335], \[344], \[348], \[411], \[415], \[426], \[444],
\[476], \[488], \[510], \[563], \[575], \[577], \[595], \[608], \[609], \[613],
\[658], \[720], \[817].
\:\\{n\_atan}, \[132], 133, 134, 140, 298, 299, 760.
\:\\{n\_cos}, \[137], 138, 303, 464, 466, 759.
\:\\{n\_fin}, \[348], 349, 350, 351, 352.
\:\\{n\_max}, \[329], 331, 333, 335, 337, 341, 659.
\:\\{n\_min}, \[329], 331, 332, 337, 341, 485.
\:\\{n\_pos}, \[329], 331, 337, 344, 347, 348.
\:\\{n\_rover}, \[329], 331, 337, 344, 347, 348.
\:\\{n\_sin}, \[137], 138, 303, 464, 466, 759.
\:\\{n\_sin\_cos}, 137, \[138], 140, 303, 464, 759.
\:\\{n\_window}, \[480], 484, 485.
\:\\{name}, 217, 497, \[499], 500, 501, 502, 505, 508, 518, 523, 524, 526, 544,
558, 568, 585, 627, 781.
\:\\{name\_field}, 78, \[497], 499.
\:\\{name\_length}, \[26], 51, 609, 613, 615.
\:\\{name\_of\_file}, \[26], 27, 51, 609, 613, 615, 620.
\:\\{name\_token}, \[180], 191, 219, 227, 235, 237, 683, 699, 705, 716.
\:\\{name\_type}, \[216], 217, 218, 219, 220, 221, 222, 223, 224, 225, 229,
230, 231, 232, 235, 237, 262, 586, 592, 593, 668, 677, 687, 715, 733.
\:\\{nd}, 630, 631.
\:\\{ne}, 630, 631.
\:\\{negate}, \[16], 63, 99, 103, 106, 111, 114, 132, 139, 255, 348, 371, 376,
381, 419, 757, 758, 765.
\:\\{negate\_dep\_list}, 757, \[758], 765.
\:\\{negate\_x}, \[132], 367, 371, 373, 419.
\:\\{negate\_y}, \[132], 367, 376, 377, 419.
\:\\{negative}, \[103], \[105], 106, \[109], \[111].
\:\\{nest\_size}, 813.
\:\\{new\_boundary}, \[389], 390, 394.
\:\\{new\_edges}, \[329].
\:\\{new\_eq}, \[252].
\:\\{new\_fragment}, 725, \[726], 736, 744.
\:\\{new\_line}, 627.
\:\\{new\_num\_tok}, \[203], 222, 716.
\:\\{new\_randoms}, 141, \[142], 143.
\:\\{new\_ring\_entry}, \[262], 711.
\:\\{new\_root}, \[219], 781.
\:\\{new\_row}, 641, \[642], 655.
\:\\{new\_string}, \[54], 57, 58, 657, 807.
\:\\{new\_structure}, \[224], 228.
\:\\{next}, \[190], 191, 194, 195.
\:\\{next\_char}, \[635].
\:\\{next\_random}, \[142], 144, 145.
\:\\{nh}, 630, 631.
\:\\{ni}, 630, 631.
\:\&{nil}, 16.
\:\\{ninety\_deg}, \[102], 134.
\:\\{nk}, 630, 631.
\:\\{nl}, \[331], 332, 630, 631.
\:\\{nn0}, \[444], 446, 450, 454, 456.
\:\\{nn1}, \[444], 446, 454.
\:\\{no\_crossing}, \[358], 359.
\:\\{no\_print}, \[54], 57, 58, 69, 91.
\:\\{no\_tag}, \[634].
\:\\{node\_size}, \[159], 162, 163, 165, 170, 176, 799, 800.
\:\.{NONEXISTENT}, 206.
\:\\{nonnegative\_integer}, 63, \[97].
\:\\{nonstop\_mode}, \[67], 80, 544, 547, 568.
\:\\{nop}, 641, 643.
\:\\{norm\_rand}, \[145], 753.
\:\\{normal}, 526, 528, 556, 560, 563, 583, 586, 587.
\:\\{normal\_deviate}, \[182], 751, 753.
\:\9{normal\_deviate\_}{\&{normaldeviate} primitive}, \[751].
\:\\{normalize\_selector}, 72, \[85], 86, 87, 88.
\:\9{not\_}{\&{not} primitive}, \[751].
\:\\{not\_found}, \[15], 45, 46, 415, 418.
\:\\{not\_op}, \[182], 751.
\:\\{nothing\_printed}, \[411], 412.
\:\\{np}, 630, 631.
\:\\{nr}, \[331], 333.
\:\\{null}, \[151], 154, 156, 158, 160, 170, 171, 175, 176, 191, 204, 205, 212,
215, 217, 219, 220, 221, 223, 227, 229, 230, 231, 234, 235, 236, 237, 239, 241,
242, 245, 248, 249, 251, 252, 254, 255, 257, 259, 260, 261, 262, 266, 268, 274,
275, 327, 339, 413, 418, 463, 465, 471, 502, 506, 508, 509, 521, 541, 550, 551,
556, 558, 560, 563, 568, 570, 574, 575, 576, 577, 578, 580, 581, 583, 584, 585,
586, 587, 594, 669, 670, 673, 675, 676, 678, 699, 705, 706, 707, 708, 712, 713,
715, 726, 727, 728, 731, 736, 743, 756, 758, 763, 764, 765, 766, 768, 769, 771,
772, 773, 774, 775, 776, 781, 785, 792, 799, 800, 814, 818.
\:\\{null\_code}, \[22].
\:\\{null\_coords}, \[168], 413.
\:\\{null\_pen}, \[168], 413, 415, 424.
\:\\{nullary}, \[180], 683, 751, 752, 753.
\:\\{null1}, \[327], 329, 332, 333, 334, 335, 338, 339, 341, 353, 486, 519,
574, 576, 660, 668.
\:\\{num}, \[108], \[302], 695.
\:\9{numeric\_}{\&{numeric} primitive}, \[783].
\:\\{numeric\_token}, \[180], 202, 203, 207, 540, 683, 684, 695, 699, 700, 706,
716, 717, 786.
\:\\{numeric\_type}, \[181], 182, 217, 227, 238, 711, 783, 784.
\:\\{nw}, 630, 631.
\:\\{n0}, \[344], 345, 346, 347, \[348], 349, 350, 351, 352, \[403], 405, 406, %
\[441], 442, 448, 452, 458.
\:\\{n1}, \[344], 345, 346, \[348], 349, 350, 351, 352, \[403], 405, 406, %
\[441], 442, 452, 458.
\:\|{o}, \[198], \[415].
\:\9{oct\_}{\&{oct} primitive}, \[751].
\:\\{oct\_op}, \[182], 751.
\:\\{octant}, \[132], 134, \[348], \[355], \[356], \[361], 362, 363, \[389], %
\[403], \[411], 412, \[415], 418, 419, 420, 421, \[441], 445, \[447], 448, 452,
458.
\:\\{octant\_code}, 386, 387, 394, 411, 420.
\:\\{octant\_number}, 386, 387, 390, 395, 418, 445.
\:\\{odd}, 61, 107, 110, 138, 395, 411, 422, 423, 445.
\:\9{odd\_}{\&{odd} primitive}, \[751].
\:\\{odd\_op}, \[182], 751.
\:\9{of\_}{\&{of} primitive}, \[199].
\:\\{of\_macro}, \[212], 215, 563, 567, 584.
\:\\{of\_token}, \[180], 199, 200.
\:\\{off\_base}, \[791], 794, 796, 800, 806.
\:\\{offset\_prep}, \[426], 429, 435, 441.
\:\\{OK\_to\_interrupt}, 82, \[89], 90, 91, 522, 685.
\:\\{old\_rover}, \[166].
\:\\{old\_setting}, 185, \[186], \[505], 506, \[624], 657.
\:\\{one\_eighty\_deg}, \[102], 132, 134.
\:\\{oo}, \[415], 418.
\:\\{op\_bit}, \[635].
\:\\{op\_defining}, 560, 564.
\:\\{op\_macro}, 560.
\:\\{open}, \[264], 268, 272, 273, 277, 278, 279, 288, 290, 291, 726, 737, 747,
748.
\:\.{open?}, 268, 272.
\:\\{open\_base\_file}, \[614], 816.
\:\\{open\_log\_file}, 72, 85, 544, 622, \[624], 625, 627, 814.
\:\\{open\_window}, \[180], 199, 200, \[482].
\:\9{open\_window\_}{\&{openwindow} primitive}, \[199].
\:\9{or\_}{\&{or} primitive}, \[751].
\:\\{or\_code}, 586, 597.
\:\\{or\_op}, \[182], 751.
\:\\{ord}, 20.
\:\9{ord\_}{\&{ord} primitive}, \[751].
\:\\{ord\_op}, \[182], 751.
\:{oriental characters}, 630.
\:\&{othercases}, \[10].
\:\\{others}, 10.
\:\.{Ouch...clobbered}, 811.
\:\\{outer\_tag}, 534.
\:\\{output}, \[4].
\:\\{output\_file\_name}, \[622], 623, 665.
\:\\{over}, \[182], 695, 751, 775.
\:\\{overflow}, 31, 42, 43, \[87], 156, 160, 195, 287, 406, 446, 454, 516, 523,
566, 585, 607, 702, 812.
\:{Overflow in arithmetic}, 9.
\:\\{o1}, 390, \[391], 394, 395.
\:\\{o2}, 390, \[391], 394, 395.
\:\|{p}, \[103], \[105], \[109], \[111], \[156], \[160], \[165], \[166], %
\[171], \[174], \[179], \[194], \[203], \[204], \[205], \[212], \[215], \[219],
\[220], \[221], \[224], \[227], \[231], \[232], \[235], \[236], \[237], \[241],
\[242], \[245], \[248], \[249], \[250], \[251], \[262], \[266], \[274], \[275],
\[305], \[331], \[335], \[337], \[339], \[341], \[344], \[348], \[353], \[361],
\[364], \[372], \[385], \[389], \[399], \[403], \[411], \[415], \[424], \[426],
\[428], \[432], \[441], \[462], \[485], \[510], \[518], \[519], \[521], \[528],
\[550], \[556], \[560], \[563], \[568], \[569], \[575], \[577], \[594], \[595],
\[658], \[668], \[669], \[670], \[673], \[676], \[678], \[683], \[711], \[712],
\[713], \[715], \[718], \[720], \[722], \[728], \[734], \[737], \[754], \[755],
\[758], \[761], \[762], \[765], \[773], \[774], \[776], \[785], \[790], \[791].
\:\\{p\_over\_v}, \[249], 776.
\:\\{p\_plus\_fq}, 243, \[245], 250, 252, 767.
\:\\{p\_times\_v}, \[248], 773.
\:\\{p\_with\_x\_becoming\_q}, \[250], 257.
\:\\{pack\_buffered\_name}, \[613], 614.
\:\\{pack\_cur\_name}, \[619], 620, 627.
\:\\{pack\_file\_name}, \[609], 619, 627.
\:\\{pack\_job\_name}, \[619], 622, 624, 807.
\:\\{page}, \[501].
\:\\{page\_stack}, \[501].
\:\\{paint}, 655.
\:\\{paint\_row}, 472, 474, \[476], 477, 479, 486, 487.
\:\\{paint\_switch}, 640, 641.
\:\\{paint\_0}, 641, \[642], 655.
\:\\{paint1}, 641, \[642], 655.
\:\\{paint2}, \[641].
\:\\{paint3}, \[641].
\:\\{pair}, 728, 760.
\:\9{pair\_}{\&{pair} primitive}, \[783].
\:\\{pair\_node\_size}, \[220], 687, 711, 726, 731, 733, 743.
\:\\{pair\_type}, \[181], 220, 667, 668, 670, 674, 679, 687, 695, 711, 731,
733, 736, 754, 755, 757, 764, 772, 774, 775, 783.
\:\\{panicking}, \[172], 173, 685, 818.
\:\\{param}, 632, 637.
\:\\{param\_level}, \[180], 213, 214, 215.
\:\\{param\_ptr}, \[503], 518, 519, 526, 585, 702.
\:\\{param\_size}, \[11], 12, 202, 503, 542, 563, 566, 585, 702, 813.
\:\\{param\_stack}, 502, \[503], 509, 519, 541, 542, 575, 585, 702.
\:\\{param\_start}, \[502], 509, 518, 519, 541, 542.
\:\\{param\_type}, 561, 562, 563, 565.
\:\\{parameter}, \[502], 508, 542.
\:\\{parent}, \[217], 222, 224, 225, 226, 230.
\:\9{PASCAL H}{\ph}, \[3], 27.
\:\9{PASCAL}{\PASCAL}, 1, 10.
\:\\{pass\_text}, 569, \[591], 597, 600.
\:\.{Path at line...}, 266.
\:\9{path\_}{\&{path} primitive}, \[783].
\:\\{path\_join}, \[180], 199, 200, 734, 735, 738, 745, 746.
\:\\{path\_size}, \[11], 285, 286, 287, 289.
\:\\{path\_type}, \[181], 667, 674, 679, 711, 722, 724, 736, 744, 748, 783, 784.
\:\\{pause\_for\_instructions}, 89, \[91].
\:\\{pausing}, \[183], 184, 547.
\:\9{pausing\_}{\&{pausing} primitive}, \[184].
\:{Peirce, Charles Santiago Sanders}, 461.
\:\9{pen\_}{\&{pen} primitive}, \[783].
\:\\{pen\_circle}, \[182], 751.
\:\9{pen\_circle\_}{\&{pencircle} primitive}, \[751].
\:\\{pen\_head}, \[441].
\:\\{pen\_node\_size}, 168, \[410], 415, 424.
\:\\{pen\_type}, \[181], 667, 674, 679, 711, 783, 784.
\:\9{penoffset\_}{\&{penoffset} primitive}, \[751].
\:\\{penoffset\_of}, \[182], 751.
\:\\{percent\_class}, \[188], 189, 205, 535.
\:\\{period\_class}, \[188], 189, 535.
\:\\{phi}, \[401].
\:\\{pixel\_color}, \[473], 474, 476, 488.
\:\.{PLAIN}, 611, 614, 810.
\:\.{Please type...}, 544, 620.
\:\\{plus}, \[182], 721, 751, 754, 761, 765.
\:\\{plus\_or\_minus}, \[180], 683, 695, 751, 752.
\:\9{point\_}{\&{point} primitive}, \[751].
\:\\{point\_of}, \[182], 751.
\:\\{pointer}, \[151], 154, 156, 159, 160, 165, 166, 171, 172, 174, 179, 190,
194, 203, 204, 212, 215, 219, 220, 221, 224, 227, 231, 232, 233, 235, 236, 237,
241, 242, 243, 245, 248, 249, 250, 251, 252, 262, 266, 274, 275, 286, 305, 329,
330, 331, 335, 336, 337, 339, 341, 348, 353, 361, 364, 372, 385, 389, 399, 403,
411, 414, 415, 424, 426, 428, 432, 441, 444, 462, 485, 503, 518, 519, 520, 521,
528, 550, 556, 560, 563, 568, 569, 575, 577, 586, 594, 595, 658, 668, 669, 670,
673, 676, 678, 683, 698, 711, 712, 713, 715, 716, 718, 720, 722, 726, 728, 734,
737, 754, 755, 758, 761, 762, 765, 771, 773, 774, 776, 779, 781, 785, 790, 791.
\:\\{pool\_file}, 47, \[50], 51, 52, 53.
\:\\{pool\_name}, \[11], 51.
\:\\{pool\_pointer}, \[38], 39, 45, 46, 59, 198, 603, 609, 656.
\:\\{pool\_ptr}, 38, \[39], 41, 42, 43, 44, 47, 52, 58, 606, 657, 797, 798,
811, 813.
\:\\{pool\_size}, \[11], 38, 42, 52, 58, 798, 813.
\:\\{pop\_input}, \[517], 519, 524.
\:\\{post}, 639, 641, \[642], 643, 644, 665.
\:\\{post\_head}, 697, \[698], 699, 706, 708.
\:\\{post\_post}, 641, \[642], 643, 644, 665.
\:\9{postcontrol\_}{\&{postcontrol} primitive}, \[751].
\:\\{postcontrol\_of}, \[182], 751.
\:\\{pp}, \[227], 228, 229, 230, \[241], \[245], 246, \[337], 338, \[364], 375,
376, 377, 378, 379, 380, 381, 382, 743, 744, 745, 746, 747.
\:\\{ppp}, \[183], 184, \[643], 665.
\:\9{ppp\_}{\&{ppp} primitive}, \[184].
\:\\{pre}, 639, 641, \[642], 657.
\:\\{pre\_head}, 697, \[698], 699, 705, 706, 707, 708.
\:\9{precontrol\_}{\&{precontrol} primitive}, \[751].
\:\\{precontrol\_of}, \[182], 751.
\:\\{prev\_dep}, \[239], 258, 259, 668, 669, 670, 715, 766.
\:\\{prev\_m}, \[341], 342, 343, \[658], 660, 661, 662.
\:\\{prev\_n}, \[658], 659, 663, 664.
\:\\{prev\_r}, 257, 258.
\:\\{prev\_ww}, \[341], 342, 343.
\:\9{primary\_}{\&{primary} primitive}, \[213], \[561].
\:\\{primary\_binary}, \[180], 182, 683, 696, 751, 752.
\:\\{primary\_def}, \[548], 549, 560.
\:\9{primary\_def\_}{\&{primarydef} primitive}, \[548].
\:\\{primary\_macro}, \[212], 213, 214, 215, 584.
\:\\{primitive}, 184, \[198], 199, 200, 213, 495, 548, 553, 561, 571, 588, 671,
739, 751, 783, 810, 811.
\:\\{print}, 54, \[59], 60, 61, 65, 67, 78, 79, 80, 83, 87, 88, 118, 127, 144,
181, 182, 187, 200, 205, 206, 207, 209, 210, 211, 214, 215, 221, 223, 241, 256,
267, 268, 269, 270, 271, 272, 273, 335, 361, 362, 363, 495, 508, 512, 513, 528,
530, 547, 549, 554, 562, 572, 576, 577, 579, 599, 608, 620, 624, 625, 626, 627,
657, 665, 672, 674, 676, 678, 684, 689, 706, 740, 755, 762, 779, 784, 797, 799,
803, 807, 812, 813, 814, 817, 818.
\:\\{print\_char}, \[58], 59, 62, 63, 64, 76, 87, 88, 99, 100, 150, 178, 179,
182, 187, 197, 207, 208, 209, 211, 215, 223, 241, 256, 258, 267, 269, 273, 335,
336, 363, 496, 507, 512, 546, 554, 626, 627, 657, 658, 665, 674, 675, 677, 684,
755, 756, 762, 763, 799, 807, 812.
\:\\{print\_cmd\_mod}, 200, 215, \[495], 496, 600, 684, 696, 814, 818.
\:\\{print\_dd}, \[64], 626, 657.
\:\\{print\_dependency}, \[241], 256, 676.
\:\\{print\_diagnostic}, 187, 266, 335, 361, 411.
\:\\{print\_dp}, 674, 675, \[676].
\:\\{print\_edges}, \[335].
\:\\{print\_err}, 66, \[67], 86, 87, 88, 91, 96, 118, 127, 133, 144, 253, 276,
366, 416, 528, 530, 537, 540, 559, 565, 579, 580, 584, 597, 600, 620, 625, 658,
684, 689, 696, 706, 717, 721, 724, 732, 738, 746, 753, 778, 779, 780, 786, 792.
\:\\{print\_esc}, 589, 597, 814.
\:\\{print\_exp}, 576, \[673], 678, 756, 763.
\:\\{print\_file\_name}, \[608], 620, 625.
\:\\{print\_int}, \[63], 78, 87, 99, 150, 175, 176, 177, 178, 179, 187, 197,
210, 223, 335, 336, 363, 507, 528, 576, 626, 657, 658, 665, 689, 797, 799, 803,
807, 814, 818.
\:\\{print\_ln}, \[57], 58, 60, 61, 65, 80, 83, 84, 150, 185, 361, 412, 508,
512, 525, 544, 547, 576, 624, 627, 678, 797, 799, 803.
\:\\{print\_locs}, \[174].
\:\\{print\_macro\_name}, 576, \[577], 579, 580, 584.
\:\\{print\_name}, 677.
\:\\{print\_nl}, \[61], 67, 76, 78, 79, 84, 175, 176, 177, 178, 179, 185, 187,
197, 256, 258, 266, 335, 336, 361, 362, 363, 411, 412, 496, 507, 508, 544, 576,
620, 624, 665, 678, 756, 763, 807, 812, 814, 817.
\:\\{print\_op}, \[182], 752, 753, 754, 755, 756, 761, 762, 763.
\:\\{print\_path}, \[266], 275, 364.
\:\\{print\_pen}, \[411], 415.
\:\\{print\_scaled}, \[99], 100, 118, 127, 144, 150, 208, 241, 258, 267, 269,
270, 273, 674, 675.
\:\\{print\_spec}, \[361], 364.
\:\\{print\_the\_digs}, \[62], 63.
\:\\{print\_token\_list}, 576.
\:\\{print\_two}, \[100], 267, 268, 271, 273, 361, 363, 411, 412.
\:\\{print\_two\_true}, \[363].
\:\\{print\_type}, \[181], 182, 674, 677, 755, 762.
\:\\{print\_variable\_name}, 209, 221, 241, 256, 258.
\:\\{print\_weight}, 335, \[336].
\:\\{print\_word}, \[150], 818.
\:\\{procrustes}, \[366].
\:\\{prompt\_file\_name}, \[620], 622, 625, 627, 807.
\:\\{prompt\_input}, \[65], 77, 81, 544, 547, 568, 620.
\:\\{proofing}, \[183], 184.
\:\9{proofing\_}{\&{proofing} primitive}, \[184].
\:\\{protection\_command}, \[180].
\:\\{proto\_dependent}, \[181], 240, 241, 245, 248, 250, 252, 258, 667, 668,
669, 670, 674, 679, 711, 714, 757, 767, 768, 773, 776.
\:\\{pseudo}, \[54], 57, 58, 511.
\:\\{psi}, \[285], 287, 296, 300, 303.
\:\\{push\_input}, \[516], 518, 523.
\:\\{put}, 26, 29, 793.
\:\\{pyth\_add}, \[120], 138, 287, 306, 392, 464, 466.
\:\\{pythag}, \[182], 751.
\:\|{q}, \[103], \[105], \[109], \[111], \[113], \[117], \[138], \[160], %
\[165], \[166], \[171], \[174], \[179], \[204], \[205], \[215], \[220], \[221],
\[224], \[227], \[231], \[235], \[236], \[237], \[241], \[245], \[250], \[262],
\[266], \[274], \[275], \[305], \[316], \[331], \[335], \[336], \[339], \[341],
\[353], \[361], \[364], \[372], \[385], \[389], \[399], \[403], \[415], \[426],
\[428], \[432], \[441], \[462], \[485], \[510], \[528], \[550], \[560], \[563],
\[575], \[577], \[594], \[595], \[658], \[669], \[670], \[676], \[683], \[712],
\[713], \[715], \[718], \[720], \[722], \[726], \[734], \[761], \[765], \[771],
\[773], \[776], \[790], \[791].
\:\\{qq}, 217, \[227], 230, \[245], 246, 247, \[337], \[364], 375, 376, 377,
378, 379, 380, 381, 382, 383, 744, 745, 747.
\:\\{qqq}, 217.
\:\\{qqqq}, 146, \[149], 150, 793, 794.
\:\\{qqq1}, 217.
\:\\{qqq2}, 217.
\:\\{qq1}, 217.
\:\\{qq2}, 217.
\:\\{quad}, 637.
\:\\{quad\_code}, \[637].
\:\\{quarter\_unit}, \[97], 401.
\:\\{quarterword}, 146, \[149], 182, 428, 497, 518, 550, 683, 753, 754, 755,
761, 762, 765.
\:\\{quote}, \[553], 555.
\:\9{quote\_}{\&{quote} primitive}, \[553].
\:\\{q1}, 217.
\:\|{r}, \[113], \[120], \[138], \[160], \[166], \[205], \[221], \[224], %
\[227], \[231], \[245], \[248], \[249], \[250], \[251], \[266], \[286], \[316],
\[337], \[339], \[341], \[348], \[364], \[372], \[389], \[403], \[414], \[415],
\[426], \[441], \[462], \[475], \[476], \[485], \[560], \[563], \[575], \[595],
\[715], \[718], \[720], \[722], \[734], \[761].
\:\\{r\_delim}, 565, \[575], 579, 580, \[683], 686, 687, \[779].
\:{Ramshaw, Lyle Harold}, 2, 407, 629.
\:\\{random\_seed}, \[180], 199, 200.
\:\9{random\_seed\_}{\&{randomseed} primitive}, \[199].
\:\\{randoms}, \[141], 142, 143, 144, 145.
\:\\{read}, 52, 53, 817, 818.
\:\\{read\_ln}, 52.
\:\9{read\_string\_}{\&{readstring} primitive}, \[751].
\:\\{read\_string\_op}, \[182], 751.
\:\\{read\_toks}, \[568].
\:\\{ready\_already}, \[810], 811.
\:\\{real}, 3, 116.
\:{recursion}, 70, 72, 231, 569, 574, 666.
\:\\{recycle\_value}, 231, 232, 519, 679, 729, 761, 771.
\:\\{ref\_count}, \[212], 413, 560, 563, 568, 708, 711, 718, 722, 734.
\:{reference counts}, 212, 502.
\:\\{relax}, \[180], 199, 200, 529.
\:\9{relax\_}{\&{relax} primitive}, \[199].
\:\\{rem\_byte}, \[635].
\:\\{remainder}, \[633], 634, 635.
\:\\{remove\_cubic}, 384, \[385], 390, 427.
\:\\{remove\_node}, \[161], 162, 164.
\:\\{rep}, \[636].
\:\9{repeat\_}{\&{repeat} primitive}, \[548].
\:\\{repeat\_the\_loop}, \[168], 556, 557.
\:\\{report\_stats}, \[180], 199, 200.
\:\9{report\_stats\_}{\&{reportstats} primitive}, \[199].
\:\\{reset}, 26, 27, 33.
\:\\{reset\_OK}, \[27].
\:\\{restart}, \[15], 533, 537, 541, 542, 544, 546, 683, 706, 707, 708, 718,
722, 734, 780.
\:\\{result}, \[45], \[46].
\:\\{reswitch}, \[15].
\:\&{return}, 15, \[16].
\:\\{return\_geq}, \[113], 114.
\:\\{reverse}, \[182], 751.
\:\9{reverse\_}{\&{reverse} primitive}, \[751].
\:\\{rewrite}, 26, 27, 33.
\:\\{rewrite\_OK}, \[27].
\:\\{rh}, 146, \[149], 150, 154, 190.
\:\\{rhs}, \[252].
\:{Riesenfeld, Richard Franklin}, 308.
\:\\{right\_brace}, \[180], 199, 200, 724.
\:\\{right\_bracket}, \[180], 199, 200, 700, 721, 782.
\:\\{right\_bracket\_class}, \[188], 189, 208, 209.
\:\\{right\_brackt}, 717.
\:\\{right\_class}, 463, 465, 467, 468, 470.
\:\\{right\_col}, \[475], \[480], 482, 485, 488, 489, 490, 493.
\:\\{right\_curl}, \[264], 267, 273, 277, 288, 300, 726, 730, 737, 747.
\:\\{right\_delimiter}, \[180], 580, 583, 779.
\:\\{right\_delta}, \[168], 288.
\:\\{right\_edge}, \[488], 489, 490.
\:\\{right\_given}, \[264], 273, 288, 299, 306, 737.
\:\\{right\_octant}, \[360], 389, 394, 395.
\:\\{right\_row}, 475.
\:\\{right\_tension}, \[264], 268, 270, 294, 295, 300, 301, 305, 307, 738, 741,
745, 746.
\:\\{right\_transition}, \[360], 395, 405, 442, 452, 458.
\:\\{right\_type}, \[263], 264, 265, 267, 268, 273, 275, 277, 278, 279, 288,
291, 296, 305, 307, 360, 362, 363, 368, 371, 372, 373, 374, 376, 377, 378, 380,
381, 382, 384, 385, 388, 389, 390, 392, 393, 404, 418, 420, 426, 428, 429, 432,
434, 445, 450, 453, 456, 463, 726, 730, 731, 733, 736, 737, 743, 744, 746, 747,
748.
\:\\{right\_u}, 463, 465, 467, 468, 470, 471.
\:\\{right\_x}, \[263], 264, 265, 267, 271, 277, 288, 305, 307, 360, 363, 366,
368, 371, 372, 373, 374, 380, 381, 382, 383, 384, 385, 393, 399, 406, 427, 431,
445, 453, 463, 731, 732, 733, 737, 743, 747.
\:\\{right\_y}, \[263], 264, 265, 267, 271, 277, 288, 305, 307, 360, 363, 366,
372, 375, 376, 377, 378, 380, 381, 382, 383, 384, 385, 393, 399, 406, 427, 431,
445, 453, 463, 731, 732, 733, 737, 743, 747.
\:\\{right\_z\_0}, 641, \[642], 655.
\:\\{right\_z\_1}, \[641].
\:\\{right\_z\_82}, \[641].
\:\\{rising}, \[432].
\:\\{rlink}, \[159], 160, 161, 162, 164, 165, 166, 167, 170, 176, 799, 800.
\:\\{root}, 217, \[218], 219, 224, 232, 237.
\:\\{rotate}, \[355], 357, 372, 380, 384, 389, 393.
\:\9{rotated\_}{\&{rotated} primitive}, \[751].
\:\\{rotated\_by}, \[182], 751.
\:\\{round\_decimals}, \[98], 99, 539.
\:\\{round\_scaled}, \[115].
\:\\{round\_trunc}, 484.
\:\\{round\_unscaled}, \[115], 344, 345, 346, 448, 451, 452, 457, 458, 626,
657, 658.
\:\\{rover}, \[159], 160, 161, 162, 163, 164, 165, 166, 167, 170, 176, 799, 800.
\:\\{row\_header\_size}, 337.
\:\\{row\_node\_size}, \[328], 332, 333, 353.
\:\\{row\_transition}, 486, \[487], 488, 490, 491, 492, 493.
\:\\{rr}, \[227], 230, \[305], \[337], 338.
\:\\{runaway}, 156, 530.
\:\\{r0}, \[482], 483, 484.
\:\\{r1}, 217, \[482], 483.
\:\|{s}, \[45], \[46], \[58], \[59], \[61], \[86], \[87], \[88], \[99], \[160],
\[165], \[187], \[198], \[220], \[224], \[227], \[245], \[248], \[249], \[250],
\[251], \[266], \[286], \[316], \[335], \[339], \[341], \[361], \[364], \[403],
\[411], \[415], \[428], \[441], \[462], \[619], \[620], \[656], \[678], \[684],
\[715], \[761], \[773], \[776].
\:\\{safety\_margin}, \[364].
\:\9{save\_}{\&{save} primitive}, \[199].
\:\\{save\_boundary\_item}, \[233].
\:\\{save\_command}, \[180], 199, 200.
\:\\{save\_cond\_ptr}, \[595], 597.
\:\\{save\_exp}, \[569].
\:\\{save\_internal}, \[236].
\:\\{save\_node\_size}, \[233], 235, 236, 237.
\:\\{save\_ptr}, \[233], 234, 235, 236, 237, 792.
\:\\{save\_scanner\_status}, \[591], \[595].
\:\\{save\_size}, \[11], 147.
\:\\{save\_variable}, \[235].
\:\\{save\_word}, \[227], 229.
\:\.{SAVED}, 221.
\:\\{saved\_equiv}, \[233], 235, 237.
\:\\{saved\_root}, \[218], 221, 235.
\:\\{sc}, 146, \[149], 150, 217, 263, 410.
\:\\{scaled}, \[97], 98, 99, 100, 101, 108, 109, 111, 115, 117, 125, 128, 143,
144, 145, 146, 149, 202, 203, 216, 217, 233, 238, 239, 240, 245, 248, 249, 255,
285, 292, 302, 309, 316, 344, 354, 355, 356, 357, 364, 369, 372, 399, 401, 403,
415, 432, 441, 444, 447, 462, 482, 641, 643, 667, 679, 776.
\:\9{scaled\_}{\&{scaled} primitive}, \[751].
\:\\{scaled\_by}, \[182], 751.
\:\\{scaled\_threshold}, \[245], 253.
\:\\{scaling\_down}, \[248], \[249].
\:\\{scan\_declared\_variable}, 564, \[781], 785.
\:\\{scan\_def}, \[563].
\:\\{scan\_expression}, 569, 582, 584, 666, 667, 681, 686, 687, 696, 717, 721,
730, 731, 732, \[734], 741, 743.
\:\\{scan\_file\_name}, \[616], 627.
\:\\{scan\_loop}, \[556], 557, 560.
\:\\{scan\_primary}, 569, 584, 666, 667, 681, \[683], 694, 695, 696, 697, 718,
751.
\:\\{scan\_secondary}, 569, 584, 666, 667, 681, \[718], 722.
\:\\{scan\_suffix}, 569, 582, \[716].
\:\\{scan\_tertiary}, 569, 584, 666, 667, 681, \[722], 734, 735.
\:\\{scan\_text}, 569.
\:\\{scan\_toks}, \[550], 556, 560, 563, 568.
\:\\{scanner\_status}, 526, 528, 556, 560, 563, 564, 583, 591, 595.
\:\\{screen\_col}, \[473], 474, 475, 476, 480, 488.
\:\\{screen\_depth}, \[11], 473, 475, 476, 483.
\:\\{screen\_OK}, \[477], 478, 482, 485.
\:\\{screen\_pixel}, \[474], 475, 476.
\:\\{screen\_row}, \[473], 474, 475, 476, 480.
\:\\{screen\_started}, \[477], 478.
\:\\{screen\_width}, \[11], 473, 475, 476, 483.
\:\\{scroll\_mode}, 65, \[67], 78, 80, 86, 620, 625.
\:\\{search\_mem}, 172, \[179], 818.
\:\\{second\_mem}, \[168], 170, 171, 175.
\:\\{second\_octant}, \[132], 134, 348, 355, 362, 387, 412, 421.
\:\9{secondary\_}{\&{secondary} primitive}, \[213].
\:\\{secondary\_binary}, \[180], 751, 752.
\:\\{secondary\_def}, \[548], 549.
\:\9{secondary\_def\_}{\&{secondarydef} primitive}, \[548].
\:\\{secondary\_macro}, \[212], 213, 214, 215, 584.
\:\\{secondary\_primary\_macro}, \[180], 718.
\:\.{see the transcript file...}, 814.
\:\\{seed}, \[143].
\:\\{selector}, \[54], 55, 57, 58, 61, 65, 69, 80, 84, 85, 91, 185, 505, 506,
511, 544, 624, 657, 807, 812, 814.
\:\\{semicolon}, \[180], 199, 200, 689.
\:\\{sentinel}, \[168], 327, 332, 333, 334, 335, 338, 339, 340, 342, 490, 660.
\:\\{set\_controls}, 303, 304, \[305], 306.
\:\\{set\_trick\_count}, \[511], 512, 513, 515.
\:\\{set\_two}, \[355].
\:\\{set\_two\_tail}, \[355].
\:\\{seventh\_octant}, \[132], 134, 348, 355, 362, 387, 412, 421.
\:\\{sf}, \[108], 303, \[304], 305, 306.
\:\9{shifted\_}{\&{shifted} primitive}, \[751].
\:\\{shifted\_by}, \[182], 751.
\:\\{ship\_out}, 645, \[658].
\:\9{ship\_out\_}{\&{shipout} primitive}, \[199].
\:\\{ship\_out\_command}, \[180], 199, 200.
\:\\{show\_cmd\_mod}, \[496], 570, 690, 753.
\:\\{show\_command}, \[180].
\:\\{show\_context}, 54, 72, 76, 82, 504, \[505], 513, 620, 625, 627.
\:\\{show\_macro}, \[215], 576.
\:\\{show\_token\_list}, \[205], 215, 221, 509, 514, 515, 577, 706, 818.
\:\9{sin\_d\_}{\&{sind} primitive}, \[751].
\:\\{sin\_d\_op}, \[182], 751, 759.
\:\\{sine}, \[286], 287, 298, 299, 306.
\:\\{single\_dependency}, 711, \[712], 715.
\:\\{sixth\_octant}, \[132], 134, 348, 355, 362, 386, 387, 412, 421.
\:\\{skew}, \[399], 405, 442.
\:\\{skew\_line\_edges}, \[447], 448, 452, 458.
\:\\{skew\_two}, \[421].
\:\\{skew\_two\_tail}, \[421].
\:\\{skip\_line}, 528, \[590], 591.
\:\\{skipping}, 528, 591.
\:\\{skip1}, 641, \[642], 664.
\:\\{skip2}, \[641], 664.
\:\\{skip3}, \[641].
\:\\{slant}, 637.
\:\\{slant\_code}, \[637].
\:\9{slanted\_}{\&{slanted} primitive}, \[751].
\:\\{slanted\_by}, \[182], 751.
\:\\{slash}, \[180], 199, 200, 695.
\:\\{slow\_case\_down}, \[348].
\:\\{slow\_case\_up}, \[348].
\:{small computers}, 152.
\:\\{small\_number}, \[97], 98, 117, 123, 128, 132, 138, 181, 198, 205, 220,
236, 241, 245, 248, 249, 250, 348, 355, 356, 361, 389, 391, 401, 403, 415, 441,
447, 550, 586, 591, 594, 595, 613, 666, 676, 698, 715, 765, 771, 773, 776, 785,
814.
\:\\{smooth\_moves}, \[325], 452, 458.
\:\.{Sorry, I can't find...}, 614.
\:\\{sort\_avail}, \[166], 799.
\:\\{sort\_edges}, \[339], 341, 486, 660.
\:\\{sorted}, 327, \[328], 332, 333, 334, 335, 338, 339, \[340], 342, 353, 488,
490, 660.
\:\\{sorted\_loc}, \[328], 338, 340.
\:\\{space}, 637.
\:\\{space\_class}, \[188], 189, 535.
\:\\{space\_code}, \[637].
\:\\{space\_shrink}, 637.
\:\\{space\_shrink\_code}, \[637].
\:\\{space\_stretch}, 637.
\:\\{space\_stretch\_code}, \[637].
\:\\{spec\_atan}, \[130], 131, 136, 140.
\:\\{spec\_head}, \[441].
\:\\{spec\_log}, \[122], 124, 126, 129.
\:\\{split\_cubic}, \[372], 373, 374, 377, 378, 382, 383, 428.
\:\\{split\_for\_offset}, \[428], 434, 438, 439.
\:\\{spotless}, \[70], 71, 185, 811, 814.
\:\\{sprint\_cs}, 530.
\:\9{sqrt\_}{\&{sqrt} primitive}, \[751].
\:\\{sqrt\_op}, \[182], 751, 759.
\:\\{square\_rt}, \[117], 118, 759.
\:\\{ss}, \[227], 228, 230, \[305], \[337], 338.
\:\\{st}, \[108], 303, \[304], 305, 306.
\:\\{st\_count}, \[190], 193, 195, 813.
\:\\{stack\_l}, \[314], 317, 318.
\:\\{stack\_m}, \[314], 317, 318.
\:\\{stack\_n}, \[314], 317, 318.
\:\\{stack\_r}, \[314], 317, 318.
\:\\{stack\_s}, \[314], 317, 318.
\:\\{stack\_size}, \[11], 498, 504, 516, 813.
\:\\{stack\_x1}, \[314], 317, 318.
\:\\{stack\_x2}, \[314], 317, 318.
\:\\{stack\_x3}, \[314], 317, 318.
\:\\{stack\_y1}, \[314], 317, 318.
\:\\{stack\_y2}, \[314], 317, 318.
\:\\{stack\_y3}, \[314], 317, 318.
\:\\{start}, 497, \[499], 500, 502, 513, 514, 518, 519, 523, 524, 526, 544,
546, 547, 568, 628.
\:\\{start\_decimal\_token}, \[533], 535.
\:\\{start\_def}, \[548], 549, 563, 564.
\:\\{start\_field}, \[497], 499.
\:\\{start\_for}, \[548], 549.
\:\\{start\_for\_suffixes}, \[548], 549.
\:\\{start\_here}, 5, \[811].
\:\\{start\_input}, 569, 571, 573, \[627], 816.
\:\\{start\_loop}, \[548], 549.
\:\\{start\_numeric\_token}, \[533], 535.
\:\\{start\_of\_MF}, \[6], 811.
\:\\{start\_of\_stmt}, \[683], 706, 709, \[734].
\:\\{start\_screen}, \[478], 482.
\:\\{stash\_cur\_exp}, 569, 581, 584, \[668], 670, 695, 696, 702, 720, 721.
\:\\{stash\_in}, 668, \[669], 687.
\:\\{stash\_temp}, 718, 722, 734.
\:\&{stat}, \[7], \[153], \[156], \[157], \[158], \[160], \[165], \[195], %
\[812], \[813].
\:\\{state}, 81, 523, 627.
\:{Stern, Moriz Abraham}, 461.
\:{Stolfi, Jorge}, 407.
\:\\{stop}, \[180].
\:\\{stop\_bit}, \[635].
\:\\{stop\_flag}, \[635].
\:\\{store\_base\_file}, \[790], 814.
\:\\{str\_eq\_buf}, \[45], 194.
\:\\{str\_eq\_str}, \[46].
\:\\{str\_number}, \[38], 39, 43, 45, 46, 47, 61, 73, 86, 87, 88, 187, 198,
202, 266, 335, 361, 411, 602, 609, 615, 617, 619, 620, 622, 656, 678, 684, 787.
\:\\{str\_pool}, 38, \[39], 42, 43, 45, 46, 47, 59, 190, 198, 211, 500, 609,
656, 797, 798, 813.
\:\\{str\_ptr}, 38, \[39], 41, 43, 44, 47, 59, 206, 607, 657, 667, 797, 798,
806, 811, 813.
\:\\{str\_room}, \[42], 195, 536, 606, 615, 807, 812.
\:\\{str\_start}, 38, \[39], 40, 41, 43, 44, 45, 46, 47, 59, 190, 198, 211,
607, 609, 656, 657, 797, 798.
\:{string pool}, 47, 796.
\:\9{string\_}{\&{string} primitive}, \[783].
\:\\{string\_class}, \[188], 189, 207, 535.
\:\\{string\_token}, \[180], 202, 207, 536, 683.
\:\\{string\_type}, \[181], 182, 667, 674, 692, 711, 783, 784.
\:\\{string\_vacancies}, \[11], 52.
\:\\{structured}, \[181], 216, 217, 218, 224, 227, 228, 231, 232, 705.
\:\\{structured\_head}, 217.
\:\\{structured\_root}, 217, \[218], 222, 224.
\:\9{subpath\_}{\&{subpath} primitive}, \[751].
\:\\{subpath\_of}, \[182], 751.
\:\\{subscr}, 217, \[218], 222, 224, 229, 231, 232.
\:\\{subscr\_head}, \[216], 217, 224, 225, 229, 231, 232, 239.
\:\\{subscr\_head\_loc}, \[216], 225, 229, 231.
\:\\{subscr\_node\_size}, \[217], 225, 229, 231, 232.
\:\\{subscript}, \[217], 222, 225, 229.
\:\\{subst\_list}, \[550], 551.
\:\9{substring\_}{\&{substring} primitive}, \[751].
\:\\{substring\_of}, \[182], 751.
\:\\{subtype}, 814.
\:\\{succumb}, \[86], 87, 88, 792.
\:\.{SUFFIX}, 210.
\:\9{suffix\_}{\&{suffix} primitive}, \[561].
\:\\{suffix\_base}, \[202], 210, 541, 542, 555, 561, 562, 580, 582.
\:\\{suffix\_count}, \[550], 555.
\:\\{suffixed\_macro}, \[181], 667, 699.
\:\\{swap\_x\_y}, 367, 381, 382, 419.
\:\\{switch}, \[533], 535, 537.
\:\\{switch\_x\_and\_y}, \[132].
\:\\{sy\_part\_loc}, \[218].
\:\\{sym}, 734.
\:{system dependencies}, 2, \[3], 4, 9, 10, 11, 12, 19, 21, 23, 26, 27, 28, 32,
33, 34, 37, 49, 56, 59, 66, 75, 78, 89, 146, 148, 149, 189, 472, 475, 476, 501,
507, 523, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 613, 615, 628,
644, 648, 650, 810, 811, 812, 817, 819.
\:\\{s1}, \[76], 82.
\:\\{s2}, \[76], 82.
\:\\{s3}, \[76], 82.
\:\|{t}, \[46], \[108], \[113], \[132], \[138], \[181], \[187], \[227], \[231],
\[241], \[245], \[250], \[286], \[316], \[369], \[372], \[428], \[432], \[518],
\[657], \[676], \[698], \[715], \[716], \[765], \[771], \[773], \[776], \[781],
\[785].
\:\\{t\_of\_the\_way}, \[372], 373, 377, 382, 434, 438, 439.
\:\\{t\_of\_the\_way\_tail}, \[372].
\:\\{t\_open\_in}, \[33], 37.
\:\\{t\_open\_out}, \[33], 811.
\:\\{tag}, \[633], 634.
\:\\{tail}, 578, 581, 584, 697, \[698], 699.
\:\\{tail\_end}, \[550].
\:\\{take\_fraction}, \[105], 108, 109, 121, 144, 145, 245, 246, 247, 248, 255,
287, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 305, 306, 307, 345,
346, 372, 392, 399, 400, 433, 451, 457, 464, 466, 695, 774.
\:\\{take\_scaled}, \[109], 245, 248, 772.
\:\\{tally}, \[54], 55, 57, 58, 205, 506, 510, 511, 512.
\:\&{tats}, \[7].
\:\\{temp}, \[441], 451, 457.
\:\\{temp\_head}, \[168], 245, 248, 249, 250, 255, 260, 338, 339, 340, 342,
550, 563, 583.
\:\\{temp\_ptr}, \[151].
\:\\{tension}, \[180], 199, 200, 738, 739, 740.
\:\9{tension\_}{\&{tension} primitive}, \[199], \[739].
\:\\{tension\_code}, \[739].
\:\\{term\_and\_log}, \[54], 57, 58, 65, 69, 85, 185, 624, 807, 814.
\:\\{term\_in}, \[32], 33, 34, 36, 37, 65, 817, 818.
\:\\{term\_input}, \[65], 72.
\:\\{term\_offset}, \[54], 55, 57, 58, 60, 61, 65, 627.
\:\\{term\_only}, \[54], 55, 57, 58, 65, 69, 85, 812, 814.
\:\\{term\_out}, \[32], 33, 34, 36, 37, 51, 56.
\:\\{terminal\_input}, \[501], 507, 523, 525, 544.
\:\\{terminator}, \[550].
\:\9{tertiary\_}{\&{tertiary} primitive}, \[213].
\:\\{tertiary\_binary}, \[180], 751, 752.
\:\\{tertiary\_def}, \[548], 549, 560.
\:\9{tertiary\_def\_}{\&{tertiarydef} primitive}, \[548].
\:\\{tertiary\_macro}, \[212], 213, 215, 584.
\:\\{tertiary\_secondary\_macro}, \[180], 235, 722.
\:\9{TeXbook}{\sl The TeXbook}, 23.
\:\.{TeXformats}, 11, 611.
\:\\{text}, \[190], 191, 194, 195, 198, 206, 508, 557, 579, 779, 803.
\:\.{TEXT}, 210.
\:\9{text\_}{\&{text} primitive}, \[561].
\:\\{text\_base}, \[202], 210, 542, 561, 562, 582.
\:\\{text\_char}, \[19], 20, 25, 27, 47.
\:\9{TFM files}{\.{TFM} files}, 629.
\:\\{tfm\_file}, \[629].
\:\\{tfm\_width}, 665.
\:\.{That makes 100 errors...}, 76.
\:\\{theta}, \[289], 297, 298, 301, 303, \[401], \[462], 464, 466.
\:\\{third\_octant}, \[132], 134, 348, 355, 360, 362, 367, 387, 412, 421.
\:\.{This can't happen}, 88.
\:\9{this can't happen b}{\quad b}, 475.
\:\9{this can't happen binary}{\quad binary}, 761.
\:\9{this can't happen dep}{\quad dep}, 241.
\:\9{this can't happen exp}{\quad exp}, 674.
\:\9{this can't happen fraction}{\quad fraction}, 103.
\:\9{this can't happen free\_node}{\quad freenode}, 165.
\:\9{this can't happen if}{\quad if}, 594.
\:\9{this can't happen nullary}{\quad nullary}, 753.
\:\9{this can't happen p}{\quad p}, 476.
\:\9{this can't happen pixels}{\quad pixels}, 660.
\:\9{this can't happen struct}{\quad struct}, 224.
\:\9{this can't happen u}{\quad u}, 472.
\:\9{this can't happen unary}{\quad unary}, 754.
\:\9{this can't happen var}{\quad var}, 222.
\:\\{this\_if}, \[595].
\:\\{three}, \[97], 302.
\:\\{three\_choices}, \[149].
\:\\{three\_quarter\_unit}, \[97], 401.
\:\\{three\_sixty\_deg}, \[102], 138.
\:\\{threshold}, \[245], 246, 247, \[248], \[249].
\:\\{time}, \[183], 184, 626, 657.
\:\9{time\_}{\&{time} primitive}, \[184].
\:\\{times}, \[182], 695, 721, 751, 772, 774.
\:\&{tini}, \[8].
\:\9{to\_}{\&{to} primitive}, \[199].
\:\\{to\_token}, \[180], 199, 200.
\:{token}, 202.
\:\\{token\_list}, \[181], 580, 581, 583, 667, 668, 679, 706, 709, 716.
\:\\{token\_node\_size}, \[202], 203, 204, 520, 550, 560, 566, 567.
\:\\{token\_state}, \[502], 521, 537, 585.
\:\\{token\_type}, \[502], 505, 506, 508, 514, 518, 519, 522.
\:\\{too\_small}, \[791], 794.
\:\\{top}, \[636].
\:\\{top\_row}, \[475], \[480], 482, 485.
\:\\{toss\_edges}, \[353], 679.
\:\\{toss\_knot\_list}, \[274], 403, 441, 679.
\:\\{toss\_pen}, \[424].
\:\\{total\_chars}, \[645], 646, 657, 658, 665.
\:\\{tracing\_choices}, \[183], 184, 275.
\:\9{tracing\_choices\_}{\&{tracingchoices} primitive}, \[184].
\:\\{tracing\_commands}, \[183], 184, 236, 570, 595, 690, 753, 754, 761.
\:\9{tracing\_commands\_}{\&{tracingcommands} primitive}, \[184].
\:\\{tracing\_edges}, \[183], 184.
\:\9{tracing\_edges\_}{\&{tracingedges} primitive}, \[184].
\:\\{tracing\_equations}, \[183], 184, 252, 258.
\:\9{tracing\_equations\_}{\&{tracingequations} primitive}, \[184].
\:\\{tracing\_macros}, \[183], 184, 575.
\:\9{tracing\_macros\_}{\&{tracingmacros} primitive}, \[184].
\:\\{tracing\_online}, \[183], 184, 185.
\:\9{tracing\_online\_}{\&{tracingonline} primitive}, \[184].
\:\\{tracing\_pens}, \[183], 184, 415.
\:\9{tracing\_pens\_}{\&{tracingpens} primitive}, \[184].
\:\\{tracing\_specs}, \[183], 184, 364.
\:\9{tracing\_specs\_}{\&{tracingspecs} primitive}, \[184].
\:\\{tracing\_stats}, 153, \[183], 184, 805, 812.
\:\9{tracing\_stats\_}{\&{tracingstats} primitive}, \[184].
\:\\{tracing\_titles}, \[183], 184.
\:\9{tracingtitles\_}{\&{tracingtitles} primitive}, \[184].
\:\\{trans\_spec}, \[473], 476, 487.
\:\9{transform\_}{\&{transform} primitive}, \[783].
\:\\{transform\_node\_size}, \[220], 711.
\:\\{transform\_type}, \[181], 220, 667, 668, 670, 674, 679, 711, 783, 784.
\:\9{transformed\_}{\&{transformed} primitive}, \[751].
\:\\{transformed\_by}, \[182], 751.
\:\\{transition}, \[401].
\:\\{trick\_buf}, \[54], 58, 510, 512.
\:\\{trick\_count}, \[54], 58, 510, 511, 512.
\:\\{true}, 4, 16, 31, 34, 37, 45, 46, 49, 51, 53, 65, 71, 82, 90, 91, 94, 103,
105, 106, 109, 111, 113, 114, 120, 128, 175, 176, 243, 246, 247, 248, 249, 266,
335, 353, 361, 366, 390, 392, 405, 411, 432, 438, 439, 442, 472, 475, 476, 477,
482, 485, 522, 523, 530, 537, 540, 545, 546, 564, 573, 576, 602, 606, 614, 673,
678, 681, 736, 745, 761, 772, 791.
\:\9{true\_}{\&{true} primitive}, \[671].
\:\\{true\_code}, 667, \[671], 672, 674.
\:\9{trunc\_}{\&{trunc} primitive}, \[751].
\:\\{trunc\_op}, \[182], 751, 759.
\:\\{trunc\_scaled}, \[115], 451, 457, 759.
\:\\{trunc\_unscaled}, \[115], 401, 446, 450, 454, 456.
\:\\{tt}, 697, \[698], 699, 705.
\:\\{two}, \[97], 98, 300, 301.
\:\\{two\_choices}, \[149].
\:\\{two\_halves}, \[149], 152, 154, 159, 179, 190.
\:\\{two\_to\_the}, \[122], 124, 126, 129, 136, 140, 260, 318, 321.
\:\\{type}, \[4], \[216], 217, 219, 220, 224, 227, 228, 229, 230, 231, 232,
238, 239, 241, 246, 247, 248, 249, 251, 257, 258, 259, 262, 564, 586, 592, 593,
594, 668, 669, 670, 673, 675, 687, 697, 699, 705, 711, 715, 729, 733, 736, 755,
757, 760, 762, 764, 765, 766, 767, 771, 772, 773, 775, 776, 785.
\:\\{type\_name}, \[180], 683, 783, 784, 785.
\:\\{t0}, \[248], \[249], \[430], \[432], 433, 438.
\:\\{t1}, \[248], \[249], \[430], \[432], 433, 434, 438.
\:\\{t2}, \[430], \[432], 433, 434, 438.
\:\|{u}, \[145], \[316], \[462].
\:\\{unary}, \[180], 683, 751, 752.
\:\\{unary\_macro}, 567.
\:\\{undefined}, \[181], 217, 219, 224, 227, 230, 232, 238, 697, 699, 705.
\:\\{undefined\_control\_sequence}, 803, 804.
\:\\{undump}, \[794], 798, 800, 804, 806.
\:\\{undump\_end}, \[794].
\:\\{undump\_end\_end}, \[794].
\:\\{undump\_four\_ASCII}, \[798].
\:\\{undump\_hh}, \[794], 804.
\:\\{undump\_int}, \[794], 796, 800, 804, 806.
\:\\{undump\_qqqq}, \[794], 798.
\:\\{undump\_size}, \[794], 798, 800.
\:\\{undump\_size\_end}, \[794].
\:\\{undump\_size\_end\_end}, \[794].
\:\\{undump\_wd}, \[794], 800.
\:\\{unequal\_to}, \[182], 751.
\:\.{Unexpected end...}, 266.
\:\\{unif\_rand}, \[144], 759.
\:\\{uniform\_deviate}, \[182], 751, 759.
\:\9{uniform\_deviate\_}{\&{uniformdeviate} primitive}, \[751].
\:\\{union}, \[182], 751.
\:\9{union\_}{\&{union} primitive}, \[751].
\:\\{unity}, \[97], 99, 108, 109, 111, 112, 115, 125, 241, 252, 255, 268, 277,
288, 294, 300, 301, 302, 307, 316, 344, 345, 346, 401, 448, 451, 452, 457, 458,
464, 540, 654, 726, 730, 737, 738, 742, 745, 746, 747, 759, 767, 776.
\:\\{unknown}, \[182], 751.
\:\.{unknown type!}, 268.
\:\9{unknown\_}{\&{unknown} primitive}, \[751].
\:\\{unknown\_boolean}, \[181], 217, 261, 667, 668, 670, 674, 679, 711.
\:\\{unknown\_edges}, \[181], 261, 667, 668, 670, 674, 679, 711.
\:\\{unknown\_path}, \[181], 261, 667, 668, 670, 674, 679, 711.
\:\\{unknown\_pen}, \[181], 261, 667, 668, 670, 674, 679, 711.
\:\\{unknown\_string}, \[181], 261, 667, 668, 670, 674, 679, 711.
\:\\{unrotate}, \[356], 357, 363, 372, 380, 384, 389, 392, 393, 412, 447.
\:\\{unsave}, \[237].
\:\\{unsorted}, 327, \[328], 329, 332, 333, 334, 335, 338, 339, 341, 345, 346,
349, 350, 351, 352, 353, 486, 660.
\:\\{unstash\_cur\_exp}, 569, \[670], 725, 736, 772, 775.
\:\\{unsuffixed}, 699.
\:\\{unsuffixed\_macro}, \[181], 667, 697, 699.
\:\9{until\_}{\&{until} primitive}, \[199].
\:\\{until\_token}, \[180], 199, 200.
\:\\{update\_screen}, \[472], 477, 479, 482, 485.
\:\\{update\_terminal}, \[34], 37, 65, 80, 472, 546, 627, 817.
\:\\{use\_err\_help}, \[73], 74, 84.
\:\\{uu}, \[289], 291, 293, 294, 296, 297, 299, 300, 301, 303.
\:\|{v}, \[203], \[205], \[241], \[248], \[249], \[250], \[372], \[432], %
\[462], \[679], \[765], \[771], \[773], \[774], \[776].
\:\\{v\_is\_scaled}, \[248], \[773].
\:\\{vacuous}, \[181], 667, 668, 669, 674, 728.
\:\\{value}, \[202], 203, 207, 208, 216, 217, 218, 220, 224, 229, 230, 231,
233, 236, 237, 238, 239, 241, 242, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 258, 259, 260, 262, 520, 543, 550, 551, 560, 564, 566, 567, 658, 667,
668, 669, 670, 673, 675, 677, 699, 707, 711, 712, 713, 715, 726, 728, 729, 731,
733, 736, 743, 755, 757, 758, 760, 764, 765, 766, 768, 769, 771, 772, 774, 775,
785.
\:\\{value\_node\_size}, \[216], 219, 224, 232, 262, 519, 668, 670, 679, 687,
695, 715, 728, 733, 761, 771, 772.
\:\\{var\_def}, \[548], 549, 563.
\:\9{var\_def\_}{\&{vardef} primitive}, \[548].
\:\\{var\_defining}, 564.
\:\\{var\_macro}, 564.
\:\\{var\_used}, \[153], 160, 165, 170, 799, 800.
\:\.{Variable...obliterated}, 706.
\:\\{velocity}, \[108], 281, 305.
\:\\{verbose}, \[673], 674, 675, \[676].
\:\.{VIRMF}, 810.
\:\\{vv}, \[289], 291, 296, 297, 299, 300, 301, 303.
\:\|{w}, \[150], \[248], \[249], \[336], \[341], \[411], \[414], \[415], %
\[424], \[426], \[432], \[444], \[488], \[658], \[773], \[776], \[790], \[791].
\:\\{w\_close}, \[28], 808, 816.
\:\\{w\_make\_name\_string}, \[615], 807.
\:\\{w\_minus}, \[341], 343.
\:\\{w\_open\_in}, \[27], 614.
\:\\{w\_open\_out}, \[27], 807.
\:\\{w\_plus}, \[341], 343.
\:\\{wake\_up\_terminal}, \[34], 37, 51, 65, 67, 547, 614, 620, 678, 791, 811,
812, 817.
\:\\{warn\_index}, 564.
\:\\{warning\_index}, 530, 556, 560, 564, 583.
\:\\{warning\_issued}, \[70], 185, 814.
\:\\{was\_free}, \[172], 174, 178.
\:\\{was\_mem\_end}, \[172], 173, 174, 178.
\:\.{WEB}, 1, 4, 38, 40, 50, 796.
\:\\{while\_loop}, 508.
\:\\{white}, \[473], 475, 476, 485, 487, 491, 493.
\:\\{width\_index}, \[633].
\:\\{winding\_number}, \[365], 388, 395.
\:\\{window\_number}, \[479], 480, 482, 485.
\:\\{window\_open}, \[480], 481, 482.
\:\\{window\_time}, \[480], 481, 482, 485.
\:{Wirth, Niklaus}, 10.
\:\\{wlog}, \[56], 58, 626, 813.
\:\\{wlog\_cr}, \[56], 57, 58, 812.
\:\\{wlog\_ln}, \[56], 813.
\:\\{word\_file}, 25, 27, 28, \[149], 615, 793.
\:\\{write}, 37, 56, 650.
\:\\{write\_gf}, \[650], 651, 652.
\:\\{write\_ln}, 37, 51, 56.
\:\\{wterm}, \[56], 58, 60, 811.
\:\\{wterm\_cr}, \[56], 57, 58.
\:\\{wterm\_ln}, \[56], 60, 614, 791.
\:\\{ww}, \[289], 291, 296, 297, 299, 300, \[341], 343, \[411], 412, \[415], %
\[424], \[426], \[432], 433, 437, 438, \[444], 446, 448, 452, 454, 458, \[488],
490, \[658], 660.
\:\|{x}, \[100], \[115], \[117], \[125], \[128], \[132], \[138], \[142], %
\[144], \[145], \[219], \[242], \[251], \[355], \[356], \[358], \[401], \[482],
\[653], \[654], \[781], \[790], \[791].
\:\\{x\_coeff}, 431.
\:\\{x\_coord}, \[263], 264, 267, 268, 269, 273, 277, 287, 288, 298, 299, 305,
306, 307, 360, 361, 363, 366, 368, 371, 372, 373, 374, 379, 380, 381, 382, 383,
384, 385, 389, 393, 399, 400, 405, 406, 410, 411, 412, 413, 414, 415, 418, 421,
423, 427, 433, 437, 442, 444, 445, 446, 448, 450, 452, 453, 454, 456, 458, 463,
467, 468, 470, 471, 726, 733, 737, 746.
\:\\{x\_height}, 637.
\:\\{x\_height\_code}, \[637].
\:\\{x\_mult}, \[182], 751.
\:\9{x\_mult\_}{\&{xmult} primitive}, \[751].
\:\\{x\_part}, \[182], 751.
\:\9{x\_part\_}{\&{xpart} primitive}, \[751].
\:\\{x\_part\_loc}, \[218], 675, 687, 726, 729, 731, 733, 743, 755, 757, 760,
764, 772, 774, 775.
\:\\{x\_part\_sector}, \[218], 220, 221, 223.
\:\\{xchr}, \[20], 21, 23, 24, 38, 49, 58, 609.
\:\&{xclause}, 16.
\:\\{xord}, \[20], 24, 31, 52, 53, 613, 615.
\:\\{xp}, \[441], 450, 451, 456, 457.
\:\\{xx}, \[358], 359, \[441], 442, 448, 450, 451, 452, 456, 457, 458.
\:\\{xx\_part}, \[182], 751.
\:\9{xx\_part\_}{\&{xxpart} primitive}, \[751].
\:\\{xx\_part\_loc}, \[218].
\:\\{xx\_part\_sector}, \[218], 223.
\:\\{xxx}, 643.
\:\\{xxx1}, 641, \[642].
\:\\{xxx2}, \[641].
\:\\{xxx3}, 641, \[642].
\:\\{xxx4}, \[641].
\:\\{xx0}, \[316], \[399], 400, \[403], 405, \[444], 446, 448, 454.
\:\\{xx1}, \[316], \[399], 400, \[444], 446, 452, 454, 458.
\:\\{xx2}, \[316].
\:\\{xx3}, \[316].
\:\\{xy\_part}, \[182], 751.
\:\9{xy\_part\_}{\&{xypart} primitive}, \[751].
\:\\{xy\_part\_sector}, \[218], 223.
\:\\{x0}, \[344], 345, 346, \[358], 359, \[430], 431, \[432], 433, 434, 436,
438, 439, 440, 442, \[447].
\:\\{x0a}, \[430], 439.
\:\\{x1}, \[316], 317, 318, 321, 322, \[344], \[358], 359, \[430], 431, \[432],
433, 434, 436, 438, 439, 440, 442, \[447].
\:\\{x1a}, \[430], 438, 439.
\:\\{x10}, 438.
\:\\{x2}, \[316], 317, 318, 321, 322, \[358], 359, \[430], 431, \[432], 433,
434, 436, 438, 439, 440.
\:\\{x2a}, \[316], 321, 322, \[430], 438.
\:\\{x3}, \[316], 317, 318, 321, 322.
\:\\{x3a}, \[316], 321, 322.
\:\|{y}, \[100], \[117], \[125], \[128], \[132], \[138], \[144], \[355], %
\[356], \[401], \[482].
\:\\{y\_coeff}, 431.
\:\\{y\_coord}, \[263], 264, 267, 268, 269, 273, 277, 287, 288, 298, 299, 305,
306, 307, 360, 361, 363, 366, 371, 372, 375, 376, 377, 378, 379, 380, 381, 382,
383, 384, 385, 389, 393, 399, 400, 405, 406, 410, 411, 412, 413, 414, 415, 418,
421, 423, 427, 433, 437, 442, 444, 445, 446, 448, 450, 452, 453, 454, 456, 458,
463, 467, 468, 470, 471, 726, 733, 737, 746.
\:\\{y\_mult}, \[182], 751.
\:\9{y\_mult\_}{\&{ymult} primitive}, \[751].
\:\\{y\_part}, \[182], 751.
\:\9{y\_part\_}{\&{ypart} primitive}, \[751].
\:\\{y\_part\_loc}, \[218], 675, 687, 726, 729, 731, 733, 743, 755, 757, 760,
764, 772, 774, 775.
\:\\{y\_part\_sector}, \[218], 223.
\:\\{year}, \[183], 184, 626, 657, 807.
\:\9{year\_}{\&{year} primitive}, \[184].
\:\.{You can't dump...}, 792.
\:\.{You have to increase POOLSIZE}, 52.
\:\.{You want to edit file x}, 78.
\:\\{yp}, \[441], 450, 451, 456, 457.
\:\\{yt}, \[344].
\:\\{yx\_part}, \[182], 751.
\:\9{yx\_part\_}{\&{yxpart} primitive}, \[751].
\:\\{yx\_part\_loc}, \[218].
\:\\{yx\_part\_sector}, \[218], 223.
\:\\{yy}, \[441], 442, 448, 450, 451, 452, 456, 457, 458.
\:\\{yy\_part}, \[182], 751.
\:\9{yy\_part\_}{\&{yypart} primitive}, \[751].
\:\\{yy\_part\_loc}, \[218].
\:\\{yy\_part\_sector}, \[218], 223.
\:\\{yy0}, \[316], \[399], 400, \[403], 405, \[444], 446, 448, 454.
\:\\{yy1}, \[316], \[399], 400, \[444], 446, 452, 454, 458.
\:\\{yy2}, \[316].
\:\\{yy3}, \[316].
\:\\{y0}, \[344], 345, 346, \[430], 431, \[432], 433, 434, 436, 438, 439, 440,
442, \[447].
\:\\{y0a}, \[430], 439.
\:\\{y1}, \[316], 317, 318, 321, 322, \[344], 345, 346, \[430], 431, \[432],
433, 434, 436, 438, 439, 440, 442, \[447].
\:\\{y1a}, \[430], 438, 439.
\:\\{y10}, 438.
\:\\{y2}, \[316], 317, 318, 321, 322, \[430], 431, \[432], 433, 434, 436, 438,
439, 440.
\:\\{y2a}, \[316], 321, 322, \[430], 438.
\:\\{y3}, \[316], 317, 318, 321, 322.
\:\\{y3a}, \[316], 321, 322.
\:\|{z}, \[125], \[128], \[132], \[138], \[336], \[341], \[488], \[658].
\:\\{z\_mult}, \[182], 751.
\:\9{z\_mult\_}{\&{zmult} primitive}, \[751].
\:\\{zero\_crossing}, \[358].
\:\\{zero\_field}, \[329], 331, 334, 335, 344, 347, 348, 485, 659.
\:\\{zero\_w}, \[327], 329, 336, 342, 343, 345, 346, 349, 350, 351, 352, 490,
660.
\fin
\:\X565:Absorb delimited arguments, putting them into lists \|q and \|r\X
\U section~563.
\:\X566:Absorb parameter tokens for type \\{base}\X
\U section~565.
\:\X567:Absorb undelimited arguments, putting them into list \|r\X
\U section~563.
\:\X766:Add a known value to the constant term of $\\{dep\_list}(\|p)$\X
\U section~765.
\:\X350:Add edges for fifth or eighth octants, then \&{goto} \\{done}\X
\U section~348.
\:\X349:Add edges for first or fourth octants, then \&{goto} \\{done}\X
\U section~348.
\:\X351:Add edges for second or third octants, then \&{goto} \\{done}\X
\U section~348.
\:\X352:Add edges for sixth or seventh octants, then \&{goto} \\{done}\X
\U section~348.
\:\X767:Add operand \|p to the dependency list \|v\X
\U section~765.
\:\X764:Add or subtract the current expression from \|p\X
\U section~761.
\:\X769:Add the known $\\{value}(\|p)$ to the constant term of \|v\X
\U section~767.
\:\X772, 775:Additional cases of binary operators\X
\U section~761.
\:\X759, 760:Additional cases of unary operators\X
\U section~754.
\:\X297:Adjust $\theta_n$ to equal $\theta_0$ and \&{goto} \\{found}\X
\U section~293.
\:\X552:Adjust the balance; \&{goto} \\{done} if it's zero\X
\U section~550.
\:\X483:Adjust the coordinates $(\\{r0},\\{c0})$ and $(\\{r1},\\{c1})$ so that
they lie in the proper range\X
\U section~482.
\:\X427:Advance \|p to node \|q, removing any ``dead'' cubics that might have
been introduced by the splitting process\X
\U section~426.
\:\X164:Allocate entire node \|p and \&{goto} \\{found}\X
\U section~162.
\:\X163:Allocate from the top of node \|p and \&{goto} \\{found}\X
\U section~162.
\:\X581:Append the current expression to \\{arg\_list}\X
\U sections~580 and~584.
\:\X222:Ascend one level, putting a token onto list \|q and replacing \|p by
its parent\X
\U section~221.
\:\X529:Back up an outer symbolic token so that it can be reread\X
\U section~528.
\:\X57, 58, 59, 61, 62, 63, 608:Basic printing procedures\X
\U section~4.
\:\X464:Calculate integers $\alpha$, $\beta$, $\gamma$ for the vertex
coordinates\X
\U section~463.
\:\X298:Calculate the given value of $\theta_n$ and \&{goto} \\{found}\X
\U section~290.
\:\X295:Calculate the ratio $\\{ff}=C_k/(C_k+B_k-u_{k-1}A_k)$\X
\U section~293.
\:\X287:Calculate the turning angles $\psi_k$ and the distances $d_{k,k+1}$;
set $n$ to the length of the path\X
\U section~284.
\:\X294:Calculate the values $\\{aa}=A_k/B_k$, $\\{bb}=D_k/C_k$, $\\{dd}=(3-%
\alpha_{k-1})d_{k,k+1}$, $\\{ee}=(3-\beta\k)d_{k-1,k}$, and $%
\\{cc}=(B_k-u_{k-1}A_k)/B_k$\X
\U section~293.
\:\X296:Calculate the values of $v_k$ and $w_k$\X
\U section~293.
\:\X200, 214, 549, 554, 562, 572, 589, 672, 740, 752, 784:Cases of \\{print%
\_cmd\_mod} for symbolic printing of primitives\X
\U section~495.
\:\X733:Change a given direction of $(0,0)$ back to a simple pair\X
\U section~724.
\:\X768:Change list $(\|t,\|v)$ to \\{proto\_dependent}\X
\U section~767.
\:\X334:Change the edge data so that $\\{m\_offset}(\\{cur\_edges})=\\{zero%
\_field}$\X
\U section~331.
\:\X448:Change the entering transition by inserting a straight line\X
\U sections~446 and~454.
\:\X80:Change the interaction level and \&{return}\X
\U section~78.
\:\X258:Change variable \|r from \\{dependent} to \\{known}\X
\U section~257.
\:\X259:Change variable \|x from \\{independent} to \\{dependent} or \\{known}\X
\U section~252.
\:\X49:Character \|k cannot be printed\X
\U section~48.
\:\X177:Check flags of unavailable nodes\X
\U section~174.
\:\X175:Check single-word \\{avail} list\X
\U section~174.
\:\X14, 147, 202, 315, 612:Check the ``constant'' values for consistency\X
\U section~811.
\:\X53:Check the pool check sum\X
\U section~52.
\:\X176:Check variable-size \\{avail} list\X
\U section~174.
\:\X748:Choose control points for the path and put the result into \\{cur\_exp}%
\X
\U section~735.
\:\X808:Close the base file\X
\U section~790.
\:\X9:Compiler directives\X
\U section~4.
\:\X416:Complain about a bad pen path\X
\U section~415.
\:\X371:Complement the \|x coordinates of the cubic between \|p and~\|q\X
\U section~368.
\:\X376:Complement the \|y coordinates of the cubic between \\{pp} and~\\{qq}\X
\U section~375.
\:\X471:Complete the ellipse by copying the negative of the half already
computed\X
\U section~462.
\:\X438:Complete the offset splitting process\X
\U section~429.
\:\X112:Compute $f=\lfloor 2↑{16}(1+p/q)+{1\over2}\rfloor$\X
\U section~111.
\:\X104:Compute $f=\lfloor 2↑{28}(1+p/q)+{1\over2}\rfloor$\X
\U section~103.
\:\X110:Compute $p=\lfloor qf/2↑{16}+{1\over2}\rfloor-q$\X
\U section~109.
\:\X107:Compute $p=\lfloor qf/2↑{28}+{1\over2}\rfloor-q$\X
\U section~105.
\:\X433:Compute test coefficients $(\\{t0},\\{t1},\\{t2})$ for $s(t)$ versus
$s_{k\pm1}$\X
\U sections~432 and~438.
\:\X400:Compute the coefficients \\{lambda}, \\{mu}, \\{alpha}, and \\{beta}\X
\U section~399.
\:\X466:Compute the distance \|d from class~0 to the edge of the ellipse in
direction $(\|u,\|v)$, times $\sqrt{u↑2+v↑2}$, rounded to the nearest integer\X
\U section~465.
\:\X196:Compute the hash code \|h\X
\U section~194.
\:\X393:Compute the incoming and outgoing directions\X
\U section~392.
\:\X484:Compute the offsets between screen coordinates and actual coordinates\X
\U section~482.
\:\X491:Consider a transition to \\{black} at column \|m\X
\U section~490.
\:\X492:Consider a transition to \\{white} at column \|m\X
\U section~490.
\:\X11:Constants in the outer block\X
\U section~4.
\:\X420:Construct the offset list for the \|kth octant\X
\U section~415.
\:\X246:Contribute a term from \|p plus \|f times the corresponding term from %
\|q\X
\U section~245.
\:\X247:Contribute a term from \|q, multiplied by~\|f\X
\U section~245.
\:\X736:Convert the left operand, \|p, into a partial path ending at~\|q; but
set $\\{abort\_path}\K\\{true}$ if \|p doesn't have a suitable type\X
\U section~735.
\:\X744:Convert the right operand, \\{cur\_exp}, into a partial path from %
\\{pp} to~\\{qq}\X
\U section~735.
\:\X139:Convert $(\|x,\|y)$ to the octant determined by~\|q\X
\U section~138.
\:\X710:Copy the variable's value into $(\\{cur\_type},\\{cur\_exp})$ and %
\&{return}\X
\U section~699.
\:\X338:Copy the \\{sorted} and \\{unsorted} lists of \|p to \\{pp}\X
\U section~337.
\:\X807:Create the \\{base\_ident}, open the base file, and inform the user
that dumping has begun\X
\U section~790.
\:\X342:Cull superfluous edge-weight entries from $\\{sorted}(\|p)$\X
\U section~341.
\:\X392:Decide whether or not to go clockwise\X
\U section~390.
\:\X790:Declare action procedures for use by \\{do\_statement}\X
\U section~778.
\:\X762, 765, 773, 776:Declare binary action procedures\X
\U section~761.
\:\X302, 305:Declare procedures needed by \\{make\_choices}\X
\U section~275.
\:\X712, 713, 715:Declare subroutines needed by \\{make\_exp\_copy}\X
\U section~711.
\:\X372, 385, 389:Declare subroutines needed by \\{make\_spec}\X
\U section~364.
\:\X428, 432:Declare subroutines needed by \\{offset\_prep}\X
\U section~426.
\:\X684, 690, 702, 704, 711, 720, 723, 726, 737, 749, 774:Declare subroutines
needed for expression parsing\X
\U section~683.
\:\X728:Declare the function called \\{known\_pair}\X
\U section~726.
\:\X614:Declare the function called \\{open\_base\_file}\X
\U section~791.
\:\X779:Declare the procedure called \\{check\_delimiter}\X
\U section~563.
\:\X771:Declare the procedure called \\{dep\_finish}\X
\U section~765.
\:\X232:Declare the procedure called \\{flush\_below\_variable}\X
\U section~231.
\:\X575:Declare the procedure called \\{macro\_call}\X
\U section~569.
\:\X495:Declare the procedure called \\{print\_cmd\_mod}\X
\U section~215.
\:\X676:Declare the procedure called \\{print\_dp}\X
\U section~673.
\:\X673:Declare the procedure called \\{print\_exp}\X
\U section~575.
\:\X577:Declare the procedure called \\{print\_macro\_name}\X
\U section~575.
\:\X336:Declare the procedure called \\{print\_weight}\X
\U section~335.
\:\X680:Declare the procedure called \\{recycle\_value}\X
\U section~231.
\:\X531:Declare the procedure called \\{runaway}\X
\U section~155.
\:\X205:Declare the procedure called \\{show\_token\_list}\X
\U section~155.
\:\X447:Declare the procedure called \\{skew\_line\_edges}\X
\U section~441.
\:\X669:Declare the procedure called \\{stash\_in}\X
\U section~668.
\:\X668, 670:Declare the stashing/unstashing routines\X
\U section~575.
\:\X755, 758:Declare unary action procedures\X
\U section~754.
\:\X119:Decrease \|k by 1, maintaining the invariant relations between \|x, %
\|y, and~\|q\X
\U section~117.
\:\X537:Decry the missing string delimiter and \&{goto} \\{restart}\X
\U section~536.
\:\X82:Delete $\|c-\.{"0"}$ tokens, \&{goto} \\{continue}\X
\U section~78.
\:\X230:Descend one level for the attribute $\\{info}(\|t)$\X
\U section~227.
\:\X229:Descend one level for the subscript $\\{value}(\|t)$\X
\U section~227.
\:\X782:Descend past a generic subscript\X
\U section~781.
\:\X578:Determine the number \|n of arguments already supplied, and set %
\\{tail} to the tail of \\{arg\_list}\X
\U section~575.
\:\X738:Determine the path join parameters\X
\U section~735.
\:\X419:Determine the \\{octant} code for direction $(\\{dx},\\{dy})$\X
\U section~418.
\:\X267:Display a fragment and \&{goto} \\{done}\X
\U section~266.
\:\X209:Display a generic subscript\X
\U section~206.
\:\X208:Display a numeric token\X
\U section~207.
\:\X675:Display a pair of numerics\X
\U section~674.
\:\X210:Display a parameter token\X
\U section~206.
\:\X677:Display a variable that's been declared but not defined\X
\U section~674.
\:\X207:Display numeric or string token\X
\U section~206.
\:\X506:Display the current context\X
\U section~505.
\:\X256:Display the new dependency\X
\U section~252.
\:\X486:Display the pixels of edge row \|p in screen row \|r\X
\U section~485.
\:\X599:Display the value of \|b\X
\U section~595.
\:\X206:Display token \|p and set \|c to its class; but \&{return} if there are
problems\X
\U section~205.
\:\X260:Divide list \|p by $2↑n$\X
\U section~259.
\:\X255:Divide list \|p by $-\|v$, removing node \|q\X
\U section~252.
\:\X515:Do magic computation\X
\U section~205.
\:\X805:Dump a couple more things and the closing check word\X
\U section~790.
\:\X795:Dump constants for consistency check\X
\U section~790.
\:\X799:Dump the dynamic memory\X
\U section~790.
\:\X803:Dump the hash table\X
\U section~790.
\:\X797:Dump the string pool\X
\U section~790.
\:\X801:Dump the table of equivalents\X
\U section~790.
\:\X652:Empty the last bytes out of \\{gf\_buf}\X
\U section~665.
\:\X72, 75, 76, 86, 87, 88:Error handling procedures\X
\U section~4.
\:\X570:Expand the current token (and subsequent ones if needed)\X
\U section~569.
\:\X585:Feed the arguments and replacement text to the scanner\X
\U section~575.
\:\X284:Fill in the control information between consecutive breakpoints \|p and
\|q\X
\U section~279.
\:\X279:Fill in the control points between \|p and the next breakpoint, then
advance \|p to that breakpoint\X
\U section~275.
\:\X278:Find the first breakpoint, \|h, on the path; insert an artificial
breakpoint if the path is an unbroken cycle\X
\U section~275.
\:\X437:Find the index \|k such that $s_{k-1}\L\\{dy}/\\{dx}<s_k$\X
\U section~429.
\:\X436:Find the initial slope, $\\{dy}/\\{dx}$\X
\U section~429.
\:\X254:Find the node \|q in list \|p whose coefficient \|v is largest\X
\U section~252.
\:\X303:Finish choosing angles and assigning control points\X
\U section~290.
\:\X534:Finish getting the symbolic token in \\{cur\_sym}\X
\U section~533.
\:\X423:Finish linking the offset nodes, and duplicate the borderline offset
nodes if necessary\X
\U section~420.
\:\X665:Finish the \.{GF} file\X
\U section~812.
\:\X395:Fix up the transition fields and adjust the winding number\X
\U section~390.
\:\X786:Flush spurious symbols after the declared variable\X
\U section~785.
\:\X543:Get a stored numeric or string token\X
\U section~541.
\:\X536:Get a string token and \&{return}\X
\U section~535.
\:\X732:Get given directions separated by commas\X
\U section~731.
\:\X745:Get ready to close a cycle\X
\U section~735.
\:\X816:Get the first line of input and prepare to start\X
\U section~811.
\:\X539:Get the fraction part \|f of a numeric token\X
\U section~535.
\:\X538:Get the integer part \|n of a numeric token; set $\|f\K0$ and \&{goto} %
\\{fin\_numeric\_token} if there is no decimal point\X
\U section~535.
\:\X291:Get the linear equations started; or \&{goto} \\{done} with the control
points in place, if linear equations needn't be solved\X
\U section~290.
\:\X77:Get user's advice and \&{return}\X
\U section~76.
\:\X13, 20, 26, 30, 32, 39, 50, 54, 67, 70, 73, 89, 94, 122, 130, 137, 141,
151, 152, 153, 154, 159, 172, 183, 186, 188, 190, 233, 243, 285, 289, 304, 312,
314, 330, 357, 365, 386, 402, 443, 474, 477, 480, 487, 494, 498, 501, 503, 504,
545, 586, 590, 602, 603, 610, 617, 622, 629, 645, 648, 666, 681, 787, 793,
810:Global variables\X
\U section~4.
\:\X127:Handle non-positive logarithm\X
\U section~125.
\:\X555:Handle quoted symbols, \.{\#\AT!}, \.{\AT!}, or \.{\AT!\#}\X
\U section~550.
\:\X118:Handle square root of zero or negative argument\X
\U section~117.
\:\X440:Handle the special case of infinite slope\X
\U section~429.
\:\X133:Handle undefined arctangent\X
\U section~132.
\:\X706:Handle unusual cases that masquerade as variables, and \&{goto} %
\\{restart} or \&{return} if appropriate\X
\U section~699.
\:\X277:If consecutive knots are equal, join them explicitly\X
\U section~275.
\:\X792:If dumping is not allowed, abort\X
\U section~790.
\:\X126:Increase \|k until \|x can be multiplied by a factor of $2↑{-k}$, and
adjust $y$ accordingly\X
\U section~125.
\:\X136:Increase \|z to the arctangent determined by $(x,y)$\X
\U section~135.
\:\X454:Initialize for dual envelope moves\X
\U section~453.
\:\X446:Initialize for ordinary envelope moves\X
\U section~445.
\:\X489:Initialize for the display computations\X
\U section~485.
\:\X170, 193, 217, 239, 327, 481, 557, 703, 789:Initialize table entries (done
by \.{INIMF} only)\X
\U section~8.
\:\X463:Initialize the ellipse data structure by beginning with directions
$(0,-1)$, $(1,0)$, $(0,1)$\X
\U section~462.
\:\X526:Initialize the input routines\X
\U section~816.
\:\X55, 60, 618, 623:Initialize the output routines\X
\U section~811.
\:\X69:Initialize the print \\{selector} based on \\{interaction}\X
\U section~816.
\:\X8:Initialize whatever \MF\ might access\X
\U section~4.
\:\X573:Initiate or terminate input from a file\X
\U section~570.
\:\X535:Input from external file; \&{goto} \\{restart} if no input found, or %
\&{return} if a non-symbolic token is found\X
\U section~533.
\:\X541:Input from token list; \&{goto} \\{restart} if end of list or if a
parameter needs to be expanded, or \&{return} if a non-symbolic token is found\X
\U section~533.
\:\X456:Insert a line segment dually to approach the correct offset\X
\U section~453.
\:\X450:Insert a line segment to approach the correct offset\X
\U section~445.
\:\X470:Insert a new line for direction $(\|u,\|v)$ between \|p and~\|q\X
\U section~465.
\:\X195:Insert a new symbolic token after \|p, then make \|p point to it and %
\&{goto} \\{found}\X
\U section~194.
\:\X542:Insert a suffix or text parameter and \&{goto} \\{restart}\X
\U section~541.
\:\X394:Insert additional boundary nodes, then \&{goto} \\{done}\X
\U section~390.
\:\X343:Insert an edge-weight for edge \|m, if the new pixel weight has changed%
\X
\U section~342.
\:\X346:Insert downward edges for a line\X
\U section~344.
\:\X388:Insert octant boundaries and compute the winding number\X
\U section~364.
\:\X390:Insert one or more octant boundary nodes just before~\|q\X
\U section~388.
\:\X458:Insert the new envelope moves dually in the pixel data\X
\U section~453.
\:\X452:Insert the new envelope moves in the pixel data\X
\U section~445.
\:\X345:Insert upward edges for a line\X
\U section~344.
\:\X332:Insert $\\{n\_min}(\\{cur\_edges})-\\{nl}$ empty rows at the bottom\X
\U section~331.
\:\X333:Insert $\\{nr}-\\{n\_max}(\\{cur\_edges})$ empty rows at the top\X
\U section~331.
\:\X465:Interpolate new vertices in the ellipse data structure until
improvement is impossible\X
\U section~462.
\:\X78:Interpret code \|c and \&{return} if done\X
\U section~77.
\:\X81:Introduce new material from the terminal and \&{return}\X
\U section~78.
\:\X746:Join the partial paths and reset \|p and \|q to the head and tail of
the result\X
\U section~735.
\:\X6:Labels in the outer block\X
\U section~4.
\:\X812, 814, 815, 817:Last-minute procedures\X
\U section~809.
\:\X226:Link a new attribute node \|r in place of node \|p\X
\U section~224.
\:\X225:Link a new subscript node \|r in place of node \|p\X
\U section~224.
\:\X422:Link node \|r to the previous node\X
\U section~420.
\:\X510:Local variables for formatting calculations\X
\U section~505.
\:\X19, 123, 169:Local variables for initialization\X
\U section~4.
\:\X286, 292:Local variables for \\{make\_choices}\X
\U section~275.
\:\X705:Look up the new values of \\{tt} and \|q\X
\U section~699.
\:\X709:Make a parameter act like a variable; \&{goto} \\{found} or \&{return}
as appropriate\X
\U section~699.
\:\X453:Make dual envelope moves for the current octant and insert them in the
pixel data\X
\U section~445.
\:\X318:Make moves for current subinterval; if bisection is necessary, push the
second subinterval onto the stack,and \&{goto} \\{continue} in order to handle
the first subinterval\X
\U section~316.
\:\X321:Make one move of each kind\X
\U section~318.
\:\X228:Make sure that both nodes \|p and \\{pp} are of \\{structured} type\X
\U section~227.
\:\X729:Make sure that both \|x and \|y parts of \|p are known\X
\U section~728.
\:\X742:Make sure the current expression is a valid tension setting\X
\U sections~741 and~741.
\:\X445:Make the envelope moves for the current octant and insert them in the
pixel data\X
\U section~441.
\:\X48:Make the first 128 strings\X
\U section~47.
\:\X406:Make the moves for the current octant\X
\U section~403.
\:\X340:Merge the \\{temp\_head} list into $\\{sorted}(\|h)$\X
\U section~339.
\:\X323:Move right then up\X
\U sections~321 and~321.
\:\X725:Move the coordinates from \|p to a new ``fragment'' node \|q\X
\U section~724.
\:\X544:Move to next line of file, or \&{goto} \\{restart} if there is no next
line, or \&{return} if a \&{readterminal} line has finished\X
\U section~535.
\:\X347:Move to row \\{n0}, pointed to by \|p\X
\U sections~345, 346, 349, 350, 351, and~352.
\:\X320:Move to the right \|m steps\X
\U section~318.
\:\X324:Move up then right\X
\U sections~321 and~321.
\:\X319:Move upward \|n steps\X
\U section~318.
\:\X129:Multiply \|y by $\exp(-z/2↑{27})$\X
\U section~128.
\:\X757:Negate the current expression\X
\U section~754.
\:\X168:Node \|p isn't in the variable-size \\{mem}\X
\U section~165.
\:\X818:Numbered cases for \\{debug\_help}\X
\U section~817.
\:\X488:Other local variables for \\{disp\_edges}\X
\U section~485.
\:\X444:Other local variables for \\{fill\_envelope}\X
\U section~441.
\:\X369, 391:Other local variables for \\{make\_spec}\X
\U section~364.
\:\X430:Other local variables for \\{offset\_prep}\X
\U section~426.
\:\X688, 698:Other local variables for \\{scan\_primary}\X
\U section~683.
\:\X813:Output statistics about this job\X
\U section~812.
\:\X770:Output the answer, \|v (which might have become \\{known})\X
\U section~767.
\:\X659:Output the character represented in \|h\X
\U section~658.
\:\X660:Output the pixels of edge row \|p to font row \|n\X
\U section~659.
\:\X540:Pack the numeric and fraction parts of a numeric token and \&{return}\X
\U section~535.
\:\X593:Pop the condition stack\X
\U sections~595, 597, and~600.
\:\X223:Preface the output with a part specifier; \&{return} in the case of a
capsule\X
\U section~221.
\:\X431:Prepare for derivative computations\X
\U section~429.
\:\X674:Print an abbreviated value of \|v with format depending on \|t\X
\U section~673.
\:\X253:Print an error message and \&{return}, since no independent variables
remain in the equation\X
\U section~252.
\:\X271:Print control points between \|p and \|q, then \&{goto} \\{done1}\X
\U section~268.
\:\X273:Print information for a curve that begins \\{curl} or \\{given}\X
\U section~268.
\:\X272:Print information for a curve that begins \\{open}\X
\U section~268.
\:\X268:Print information for adjacent knots \|p and \|q\X
\U section~266.
\:\X507:Print location of current line\X
\U section~506.
\:\X178:Print newly busy locations\X
\U section~174.
\:\X269:Print previous \\{given} or \\{curl}\X
\U sections~268 and~273.
\:\X270:Print tension between \|p and \|q\X
\U section~268.
\:\X626:Print the banner line, including the date and time\X
\U section~624.
\:\X363:Print the cubic between \|p and \|q\X
\U section~362.
\:\X362:Print the cubic or the octant boundary between \|p and \|q\X
\U section~361.
\:\X83:Print the help information, \&{goto} \\{continue}\X
\U section~78.
\:\X79:Print the menu of available options\X
\U section~78.
\:\X509:Print the name of a \&{vardef}'d macro\X
\U section~508.
\:\X412:Print the unskewed and unrotated coordinates of node \\{ww}\X
\U section~411.
\:\X211:Print the \|rth string as a symbolic token and set \|c to its class\X
\U section~206.
\:\X512:Print two lines using the tricky pseudoprinted information\X
\U section~506.
\:\X508:Print type of token list\X
\U section~506.
\:\X513:Pseudoprint the line\X
\U section~506.
\:\X514:Pseudoprint the token list\X
\U section~506.
\:\X592:Push the condition stack\X
\U section~595.
\:\X730:Put a curl specification into fragment \|q\X
\U section~724.
\:\X731:Put a given direction into fragment \|q\X
\U section~724.
\:\X184, 199, 213, 548, 553, 561, 571, 588, 671, 739, 751, 783:Put each of %
\MF's primitives into the hash table\X
\U section~815.
\:\X84:Put help message on the transcript file\X
\U section~76.
\:\X701:Put the left bracket and the expression back to be rescanned\X
\U sections~700 and~721.
\:\X546:Read next line of file into \\{buffer}, or \&{goto} \\{restart} if the
file has ended\X
\U section~544.
\:\X52:Read one string, but return \\{false} if the string memory space is
getting too tight for comfort\X
\U section~51.
\:\X628:Read the first line of the new file\X
\U section~627.
\:\X51:Read the other strings from the \.{MF.POOL} file and return \\{true}, or
give an error message and return \\{false}\X
\U section~47.
\:\X457:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},\\{yp})$
dually in \\{env\_move}\X
\U section~456.
\:\X451:Record a line segment from $(\\{xx},\\{yy})$ to $(\\{xp},\\{yp})$ in %
\\{env\_move}\X
\U section~450.
\:\X307:Reduce to simple case of straight line and \&{goto} \\{done}\X
\U section~291.
\:\X306:Reduce to simple case of two givens and \&{goto} \\{done}\X
\U section~291.
\:\X114:Reduce to the case that $\|a,\|c\G0$, $\|b,\|d>0$\X
\U section~113.
\:\X106:Reduce to the case that $\|f\G0$ and $\|q>0$\X
\U sections~105 and~109.
\:\X317:Remove a subproblem for \\{make\_moves} from the stack\X
\U section~316.
\:\X469:Remove and move past the line from \|q to \|r\X
\U section~467.
\:\X384:Remove dead cubics\X
\U section~364.
\:\X467:Remove the line from \|p to \|q, and adjust vertex~\|q to introduce a
new line\X
\U section~465.
\:\X468:Remove the line from \|q to \|r, and adjust vertex~\|q to introduce a
new line\X
\U section~465.
\:\X288:Remove \\{open} types at the breakpoints\X
\U section~284.
\:\X121:Replace \|a by an approximation to $\sqrt{a↑2+b↑2}$\X
\U section~120.
\:\X276:Report an unexpected problem during the choice-making\X
\U section~275.
\:\X777:Report division by zero error\X
\U section~775.
\:\X134:Return an appropriate answer based on \|z and \\{octant}\X
\U section~132.
\:\X370:Scale up \\{del1}, \\{del2}, and \\{del3} for greater accuracy; also
set \\{del} to the first nonzero element of $(\\{del1},\\{del2},\\{del3})$\X
\U sections~368, 375, and~379.
\:\X696:Scan a binary operation with `\&{of}' between its operands\X
\U section~683.
\:\X691:Scan a boolean constant\X
\U section~683.
\:\X717:Scan a bracketed subscript and set $\\{cur\_cmd}\K\\{numeric\_token}$\X
\U section~716.
\:\X686:Scan a delimited primary\X
\U section~683.
\:\X724:Scan a direction specification\X
\U section~722.
\:\X689:Scan a grouped primary\X
\U section~683.
\:\X721:Scan a mediation construction\X
\U section~718.
\:\X693:Scan a nullary operation\X
\U section~683.
\:\X735:Scan a path construction operation\X
\U section~734.
\:\X695:Scan a primary that starts with a numeric token\X
\U section~683.
\:\X692:Scan a string constant\X
\U section~683.
\:\X583:Scan a text parameter delimited by $\\{l\_delim},\\{r\_delim}$\X
\U section~582.
\:\X694:Scan a unary operation\X
\U section~683.
\:\X699:Scan a variable primary; \&{goto} \\{restart} if it turns out to be a
macro\X
\U section~683.
\:\X621:Scan file name in the buffer\X
\U section~620.
\:\X700:Scan for a subscript; replace \\{cur\_cmd} by \\{numeric\_token} if
found\X
\U section~699.
\:\X582:Scan the argument represented by $\\{info}(\|r)$\X
\U section~580.
\:\X580:Scan the delimited argument represented by $\\{info}(\|r)$\X
\U section~579.
\:\X579:Scan the remaining arguments, if any; set \|r to the first token of the
replacement text\X
\U section~575.
\:\X687:Scan the second of a pair of numerics\X
\U section~686.
\:\X564:Scan the token or variable to be defined; set \|n, \\{scanner\_status},
and \\{warning\_index}\X
\U section~563.
\:\X584:Scan undelimited argument(s)\X
\U section~579.
\:\X197:Search \\{eqtb} for equivalents equal to \|p\X
\U section~179.
\:\X743:Set explicit control points\X
\U section~738.
\:\X741:Set explicit tensions\X
\U section~738.
\:\X21, 23, 24, 68, 71, 74, 90, 95, 124, 131, 173, 189, 191, 234, 244, 313,
387, 413, 478, 587, 611, 646, 649, 667, 682, 788:Set initial values of key
variables\X
\U section~8.
\:\X301:Set up equation for a curl at $\theta_n$ and \&{goto} \\{found}\X
\U section~290.
\:\X293:Set up equation to match mock curvatures at $z_k$; then \&{goto} %
\\{found} with $\theta_n$ adjusted to equal $\theta_0$, if a cycle has ended\X
\U section~290.
\:\X708:Set up suffixed macro call and \&{goto} \\{restart}\X
\U section~706.
\:\X300:Set up the equation for a curl at $\theta_0$\X
\U section~291.
\:\X299:Set up the equation for a given value of $\theta_0$\X
\U section~291.
\:\X490:Set up the parameters needed for \\{paint\_row}; but \&{goto} \\{done}
if no painting is needed after all\X
\U section~486.
\:\X707:Set up unsuffixed macro call and \&{goto} \\{restart}\X
\U section~699.
\:\X380:Set up $(\\{del1},\\{del2},\\{del3})$ to represent $x'-y'$\X
\U section~379.
\:\X598:Set \|b to the value of a boolean condition\X
\U section~595.
\:\X404:Set \|q to the node at the end of the current octant\X
\U sections~403 and~441.
\:\X135:Set \|z to the arctangent determined by $(x,y)$\X
\U section~132.
\:\X576:Show the text of the macro being expanded, and the existing arguments\X
\U section~575.
\:\X257:Simplify all existing dependencies by substituting for \|x\X
\U section~252.
\:\X442:Skew all the coordinates between \|p and \|q; set $(\\{m0},\\{n0})$ and
$(\\{m1},\\{n1})$ to the starting and ending envelope lattice points\X
\U section~441.
\:\X405:Skew all the coordinates between \|p and \|q; set $(\\{m0},\\{n0})$ and
$(\\{m1},\\{n1})$ to the starting and ending lattice points\X
\U section~403.
\:\X664:Skip to $(m,n)$\X
\U section~663.
\:\X597:Skip to \&{elseif} or \&{else} or \&{fi}, then \&{goto} \\{common}%
\\{ending}\X
\U section~595.
\:\X290:Solve linear equations and fill in the control information between
breakpoints \|p and~\|q, unless a simple case makes the calculations
unnecessary\X
\U section~284.
\:\X167:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X
\U section~166.
\:\X747:Splice independent paths together\X
\U section~746.
\:\X439:Split off another \\{rising} cubic for \\{fin\_offset\_prep}\X
\U section~438.
\:\X434:Split the cubic at $t$, and split off another cubic if the derivative
crosses back\X
\U section~432.
\:\X429:Split the cubic between \|p and \|q, if necessary, into cubics
associated with single offsets, after which \|q should point to the end of the
final such cubic\X
\U section~426.
\:\X418:Stamp all nodes with an octant code, and set \\{hh} to the node that
begins the first octant; \&{goto} \\{not\_found} if there's a problem\X
\U section~415.
\:\X663:Start a new row at $(m,n)$\X
\U section~661.
\:\X661:Start black at $(m,n)$\X
\U section~660.
\:\X662:Stop black at $(m,n)$\X
\U section~660.
\:\X379:Subdivide all cubics between \|p and \|q so that the results travel
toward the first octant\X
\U section~367.
\:\X375:Subdivide all cubics between \|p and \|q so that the results travel
toward the first quadrant\X
\U section~367.
\:\X367:Subdivide each cubic into octants\X
\U section~364.
\:\X374:Subdivide the cubic a second time with respect to $x'$\X
\U section~373.
\:\X383:Subdivide the cubic a second time with respect to $x'-y'$\X
\U section~382.
\:\X378:Subdivide the cubic a second time with respect to $y'$\X
\U section~377.
\:\X368:Subdivide the cubic between \|p and \|q so that the results travel
toward the right halfplane\X
\U section~367.
\:\X373:Subdivide the cubic with respect to $x'$, possibly twice\X
\U section~368.
\:\X382:Subdivide the cubic with respect to $x'-y'$, possibly twice\X
\U section~379.
\:\X377:Subdivide the cubic with respect to $y'$, possibly twice\X
\U section~375.
\:\X551:Substitute for \\{cur\_sym} if it's on the \\{subst\_list}\X
\U section~550.
\:\X140:Subtract angle \|z from $(\|x,\|y)$\X
\U section~138.
\:\X685:Supply diagnostic information, if requested\X
\U section~683.
\:\X381:Swap the \|x and \|y coordinates of the cubic between \\{pp} and~\\{qq}%
\X
\U section~379.
\:\X322:Switch to the right subinterval\X
\U section~321.
\:\X530:Tell the user what has run away and try to recover\X
\U section~528.
\:\X600:Terminate the current conditional and skip to \&{fi}\X
\U section~570.
\:\X763:Trace the current binary operation\X
\U section~761.
\:\X756:Trace the current unary operation\X
\U section~754.
\:\X455:Transfer moves dually from the \\{move} array to \\{env\_move}\X
\U section~453.
\:\X449:Transfer moves from the \\{move} array to \\{env\_move}\X
\U section~445.
\:\X421:Transform the coordinates of node \|q to \\{octant}, skewed, and put
them into node \|r\X
\U section~420.
\:\X366:Truncate the values of all coordinates that are too large, and stamp
serial numbers in each \\{left\_type} field\X
\U section~364.
\:\X162:Try to allocate within node \|p and its physical successors, and %
\&{goto} \\{found} if allocation was possible\X
\U section~160.
\:\X625:Try to get a different log file name\X
\U section~624.
\:\X18, 25, 38, 97, 101, 102, 149, 473, 479, 497, 647:Types in the outer block\X
\U section~4.
\:\X806:Undump a couple more things and the closing check word\X
\U section~791.
\:\X796:Undump constants for consistency check\X
\U section~791.
\:\X800:Undump the dynamic memory\X
\U section~791.
\:\X804:Undump the hash table\X
\U section~791.
\:\X798:Undump the string pool\X
\U section~791.
\:\X802:Undump the table of equivalents\X
\U section~791.
\:\X359:Use bisection to find the crossing point, if one exists\X
\U section~358.
\:\X493:Wind up the \\{paint\_row} parameter calculation by inserting the final
transition; \&{goto} \\{done} if no painting is needed\X
\U section~490.
\con